Skip to content

Commit deab631

Browse files
Merge pull request #4160 from adrian-prantl/91007207-2
Make triple deduction more robust against strange environments.
2 parents bac821a + bb0a9c4 commit deab631

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,18 +2250,30 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
22502250
target_triple.str().c_str());
22512251
computed_triple = target_triple;
22522252
} else {
2253+
// Underspecified means that one or more of vendor, os, or os
2254+
// version (Darwin only) is missing.
22532255
LOG_PRINTF(GetLog(LLDBLog::Types), "Underspecified target triple %s.",
22542256
target_triple.str().c_str());
22552257
PlatformSP platform_sp(target.GetPlatform());
2256-
if (platform_sp && !target_triple.hasEnvironment()) {
2258+
// Try to fill in the platform OS version. Don't do this when an
2259+
// environment is present, since there might be some ambiguity
2260+
// about the plaform (e.g., ios-macabi runs on the macOS, but
2261+
// uses iOS version numbers).
2262+
if (platform_sp &&
2263+
target_triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
22572264
llvm::VersionTuple version =
22582265
platform_sp->GetOSVersion(target.GetProcessSP().get());
2259-
std::string buffer;
2260-
llvm::raw_string_ostream(buffer)
2261-
<< target_triple.getArchName() << '-'
2262-
<< target_triple.getVendorName() << '-'
2263-
<< llvm::Triple::getOSTypeName(target_triple.getOS())
2264-
<< version.getAsString();
2266+
llvm::SmallString<32> buffer;
2267+
{
2268+
llvm::raw_svector_ostream os(buffer);
2269+
os << target_triple.getArchName() << '-';
2270+
os << target_triple.getVendorName() << '-';
2271+
os << llvm::Triple::getOSTypeName(target_triple.getOS());
2272+
os << version.getAsString();
2273+
StringRef env = target_triple.getEnvironmentName();
2274+
if (!env.empty())
2275+
os << '-' << env;
2276+
}
22652277
computed_triple = llvm::Triple(buffer);
22662278
} else {
22672279
computed_triple = get_executable_triple();

0 commit comments

Comments
 (0)