@@ -2351,23 +2351,27 @@ llvm::Triple SwiftASTContext::GetTriple() const {
2351
2351
return llvm::Triple (m_compiler_invocation_ap->getTargetTriple ());
2352
2352
}
2353
2353
2354
- // / Conditions a triple string to be safe for use with Swift.
2355
- // /
2356
- // / This strips the Haswell marker off the CPU name (for Apple targets).
2357
- // /
2358
- // / It also add the GNU environment for Linux. Although this is technically
2359
- // / incorrect, as the `*-unknown-linux` environment represents the bare-metal
2360
- // / environment, because Swift is currently hosted only, we can get away with
2361
- // / it.
2362
- // /
2363
- // / TODO: Make Swift more robust.
2364
- static std::string GetSwiftFriendlyTriple (llvm::Triple triple) {
2365
- if (triple.getArchName () == " x86_64h" )
2366
- triple.setArch (llvm::Triple::x86_64);
2367
- if (triple.isOSLinux () &&
2368
- triple.getEnvironment () == llvm::Triple::UnknownEnvironment)
2369
- triple.setEnvironment (llvm::Triple::GNU);
2370
- return triple.normalize ();
2354
+ llvm::Triple SwiftASTContext::GetSwiftFriendlyTriple (llvm::Triple triple) {
2355
+ if (triple.getVendor () != llvm::Triple::Apple) {
2356
+ // Add the GNU environment for Linux. Although this is
2357
+ // technically incorrect, as the `*-unknown-linux` environment
2358
+ // represents the bare-metal environment, because Swift is
2359
+ // currently hosted only, we can get away with it.
2360
+ if (triple.isOSLinux () &&
2361
+ triple.getEnvironment () == llvm::Triple::UnknownEnvironment)
2362
+ triple.setEnvironment (llvm::Triple::GNU);
2363
+ triple.normalize ();
2364
+ return triple;
2365
+ }
2366
+
2367
+ StringRef arch_name = triple.getArchName ();
2368
+ if (arch_name == " x86_64h" )
2369
+ triple.setArchName (" x86_64" );
2370
+ else if (arch_name == " aarch64" )
2371
+ triple.setArchName (" arm64" );
2372
+ else if (arch_name == " aarch64_32" )
2373
+ triple.setArchName (" arm64_32" );
2374
+ return triple;
2371
2375
}
2372
2376
2373
2377
bool SwiftASTContext::SetTriple (const llvm::Triple triple, Module *module ) {
@@ -2385,18 +2389,15 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
2385
2389
}
2386
2390
2387
2391
const unsigned unspecified = 0 ;
2388
- std::string adjusted_triple = GetSwiftFriendlyTriple (triple);
2392
+ llvm::Triple adjusted_triple = GetSwiftFriendlyTriple (triple);
2389
2393
// If the OS version is unspecified, do fancy things.
2390
2394
if (triple.getOSMajorVersion () == unspecified) {
2391
2395
// If a triple is "<arch>-apple-darwin" change it to be
2392
2396
// "<arch>-apple-macosx" otherwise the major and minor OS
2393
2397
// version we append below would be wrong.
2394
2398
if (triple.getVendor () == llvm::Triple::VendorType::Apple &&
2395
- triple.getOS () == llvm::Triple::OSType::Darwin) {
2396
- llvm::Triple mac_triple (adjusted_triple);
2397
- mac_triple.setOS (llvm::Triple::OSType::MacOSX);
2398
- adjusted_triple = mac_triple.str ();
2399
- }
2399
+ triple.getOS () == llvm::Triple::OSType::Darwin)
2400
+ adjusted_triple.setOS (llvm::Triple::OSType::MacOSX);
2400
2401
2401
2402
// Append the min OS to the triple if we have a target
2402
2403
ModuleSP module_sp;
@@ -2411,12 +2412,9 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
2411
2412
2412
2413
if (module ) {
2413
2414
if (ObjectFile *objfile = module ->GetObjectFile ())
2414
- if (llvm::VersionTuple version = objfile->GetMinimumOSVersion ()) {
2415
- llvm::Triple vers_triple (adjusted_triple);
2416
- vers_triple.setOSName (vers_triple.getOSName ().str () +
2417
- version.getAsString ());
2418
- adjusted_triple = vers_triple.str ();
2419
- }
2415
+ if (llvm::VersionTuple version = objfile->GetMinimumOSVersion ())
2416
+ adjusted_triple.setOSName (adjusted_triple.getOSName ().str () +
2417
+ version.getAsString ());
2420
2418
}
2421
2419
}
2422
2420
if (llvm::Triple (triple).getOS () == llvm::Triple::UnknownOS) {
@@ -2425,15 +2423,14 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
2425
2423
return false ;
2426
2424
}
2427
2425
LOG_PRINTF (LIBLLDB_LOG_TYPES, " (\" %s\" ) setting to \" %s\" " ,
2428
- triple.str ().c_str (), adjusted_triple.c_str ());
2426
+ triple.str ().c_str (), adjusted_triple.str (). c_str ());
2429
2427
2430
- llvm::Triple adjusted_llvm_triple (adjusted_triple);
2431
- m_compiler_invocation_ap->setTargetTriple (adjusted_llvm_triple);
2428
+ m_compiler_invocation_ap->setTargetTriple (adjusted_triple);
2432
2429
2433
- assert (GetTriple () == adjusted_llvm_triple );
2430
+ assert (GetTriple () == adjusted_triple );
2434
2431
assert (!m_ast_context_ap ||
2435
2432
(llvm::Triple (m_ast_context_ap->LangOpts .Target .getTriple ()) ==
2436
- adjusted_llvm_triple ));
2433
+ adjusted_triple ));
2437
2434
2438
2435
// Every time the triple is changed the LangOpts must be updated
2439
2436
// too, because Swift default-initializes the EnableObjCInterop
0 commit comments