Skip to content

Commit 59561be

Browse files
authored
Merge pull request #1577 from compnerd/triple-fun
TypeSystem: extend the triple sanitization for Swift
2 parents f59d544 + b0b8291 commit 59561be

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -2347,14 +2347,23 @@ llvm::Triple SwiftASTContext::GetTriple() const {
23472347
return llvm::Triple(m_compiler_invocation_ap->getTargetTriple());
23482348
}
23492349

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.
23522358
///
23532359
/// 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();
23582367
}
23592368

23602369
bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
@@ -2372,7 +2381,7 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
23722381
}
23732382

23742383
const unsigned unspecified = 0;
2375-
std::string adjusted_triple = GetSwiftFriendlyTriple(triple.str());
2384+
std::string adjusted_triple = GetSwiftFriendlyTriple(triple);
23762385
// If the OS version is unspecified, do fancy things.
23772386
if (triple.getOSMajorVersion() == unspecified) {
23782387
// If a triple is "<arch>-apple-darwin" change it to be

0 commit comments

Comments
 (0)