@@ -2347,14 +2347,23 @@ llvm::Triple SwiftASTContext::GetTriple() const {
2347
2347
return llvm::Triple (m_compiler_invocation_ap->getTargetTriple ());
2348
2348
}
2349
2349
2350
- // / Conditions a triple string to be safe for use with Swift. Right
2351
- // / now this just strips the Haswell marker off the CPU name.
2350
+ // / Conditions a triple string to be safe for use with Swift.
2351
+ // /
2352
+ // / This strips the Haswell marker off the CPU name (for Apple targets).
2353
+ // /
2354
+ // / It also add the GNU environment for Linux. Although this is technically
2355
+ // / incorrect, as the `*-unknown-linux` environment represents the bare-metal
2356
+ // / environment, because Swift is currently hosted only, we can get away with
2357
+ // / it.
2352
2358
// /
2353
2359
// / TODO: Make Swift more robust.
2354
- static std::string GetSwiftFriendlyTriple (StringRef triple) {
2355
- if (triple.consume_front (" x86_64h" ))
2356
- return std::string (" x86_64" ) + triple.str ();
2357
- return triple.str ();
2360
+ static std::string GetSwiftFriendlyTriple (llvm::Triple triple) {
2361
+ if (triple.getArchName () == " x86_64h" )
2362
+ triple.setArch (llvm::Triple::x86_64);
2363
+ if (triple.isOSLinux () &&
2364
+ triple.getEnvironment () == llvm::Triple::UnknownEnvironment)
2365
+ triple.setEnvironment (llvm::Triple::GNU);
2366
+ return triple.normalize ();
2358
2367
}
2359
2368
2360
2369
bool SwiftASTContext::SetTriple (const llvm::Triple triple, Module *module) {
@@ -2372,7 +2381,7 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
2372
2381
}
2373
2382
2374
2383
const unsigned unspecified = 0 ;
2375
- std::string adjusted_triple = GetSwiftFriendlyTriple (triple. str () );
2384
+ std::string adjusted_triple = GetSwiftFriendlyTriple (triple);
2376
2385
// If the OS version is unspecified, do fancy things.
2377
2386
if (triple.getOSMajorVersion () == unspecified) {
2378
2387
// If a triple is "<arch>-apple-darwin" change it to be
0 commit comments