@@ -2319,14 +2319,20 @@ llvm::Triple SwiftASTContext::GetTriple() const {
2319
2319
return llvm::Triple (m_compiler_invocation_ap->getTargetTriple ());
2320
2320
}
2321
2321
2322
- // / Conditions a triple string to be safe for use with Swift. Right
2323
- // / now this just strips the Haswell marker off the CPU name.
2322
+ // / Conditions a triple string to be safe for use with Swift. Swift
2323
+ // / is really peculiar about what CPU types it thinks it has standard
2324
+ // / libraries for.
2324
2325
// /
2325
2326
// / TODO: Make Swift more robust.
2326
- static std::string GetSwiftFriendlyTriple (StringRef triple) {
2327
- if (triple.consume_front (" x86_64h" ))
2328
- return std::string (" x86_64" ) + triple.str ();
2329
- return triple.str ();
2327
+ llvm::Triple SwiftASTContext::GetSwiftFriendlyTriple (llvm::Triple triple) {
2328
+ StringRef arch_name = triple.getArchName ();
2329
+ if (arch_name == " x86_64h" )
2330
+ triple.setArchName (" x86_64" );
2331
+ else if (arch_name == " aarch64" )
2332
+ triple.setArchName (" arm64" );
2333
+ else if (arch_name == " aarch64_32" )
2334
+ triple.setArchName (" arm64_32" );
2335
+ return triple;
2330
2336
}
2331
2337
2332
2338
bool SwiftASTContext::SetTriple (const llvm::Triple triple, Module *module ) {
@@ -2344,18 +2350,15 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
2344
2350
}
2345
2351
2346
2352
const unsigned unspecified = 0 ;
2347
- std::string adjusted_triple = GetSwiftFriendlyTriple (triple. str () );
2353
+ llvm::Triple adjusted_triple = GetSwiftFriendlyTriple (triple);
2348
2354
// If the OS version is unspecified, do fancy things.
2349
2355
if (triple.getOSMajorVersion () == unspecified) {
2350
2356
// If a triple is "<arch>-apple-darwin" change it to be
2351
2357
// "<arch>-apple-macosx" otherwise the major and minor OS
2352
2358
// version we append below would be wrong.
2353
2359
if (triple.getVendor () == llvm::Triple::VendorType::Apple &&
2354
- triple.getOS () == llvm::Triple::OSType::Darwin) {
2355
- llvm::Triple mac_triple (adjusted_triple);
2356
- mac_triple.setOS (llvm::Triple::OSType::MacOSX);
2357
- adjusted_triple = mac_triple.str ();
2358
- }
2360
+ triple.getOS () == llvm::Triple::OSType::Darwin)
2361
+ adjusted_triple.setOS (llvm::Triple::OSType::MacOSX);
2359
2362
2360
2363
// Append the min OS to the triple if we have a target
2361
2364
ModuleSP module_sp;
@@ -2370,12 +2373,9 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
2370
2373
2371
2374
if (module ) {
2372
2375
if (ObjectFile *objfile = module ->GetObjectFile ())
2373
- if (llvm::VersionTuple version = objfile->GetMinimumOSVersion ()) {
2374
- llvm::Triple vers_triple (adjusted_triple);
2375
- vers_triple.setOSName (vers_triple.getOSName ().str () +
2376
- version.getAsString ());
2377
- adjusted_triple = vers_triple.str ();
2378
- }
2376
+ if (llvm::VersionTuple version = objfile->GetMinimumOSVersion ())
2377
+ adjusted_triple.setOSName (adjusted_triple.getOSName ().str () +
2378
+ version.getAsString ());
2379
2379
}
2380
2380
}
2381
2381
if (llvm::Triple (triple).getOS () == llvm::Triple::UnknownOS) {
@@ -2384,15 +2384,14 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
2384
2384
return false ;
2385
2385
}
2386
2386
LOG_PRINTF (LIBLLDB_LOG_TYPES, " (\" %s\" ) setting to \" %s\" " ,
2387
- triple.str ().c_str (), adjusted_triple.c_str ());
2387
+ triple.str ().c_str (), adjusted_triple.str (). c_str ());
2388
2388
2389
- llvm::Triple adjusted_llvm_triple (adjusted_triple);
2390
- m_compiler_invocation_ap->setTargetTriple (adjusted_llvm_triple);
2389
+ m_compiler_invocation_ap->setTargetTriple (adjusted_triple);
2391
2390
2392
- assert (GetTriple () == adjusted_llvm_triple );
2391
+ assert (GetTriple () == adjusted_triple );
2393
2392
assert (!m_ast_context_ap ||
2394
2393
(llvm::Triple (m_ast_context_ap->LangOpts .Target .getTriple ()) ==
2395
- adjusted_llvm_triple ));
2394
+ adjusted_triple ));
2396
2395
2397
2396
// Every time the triple is changed the LangOpts must be updated
2398
2397
// too, because Swift default-initializes the EnableObjCInterop
0 commit comments