Skip to content

Commit 53be54f

Browse files
committed
Merge commit '5277e07dbe35' from swift/release/5.3 into swift/master
Conflicts: lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
2 parents 438d89c + 5277e07 commit 53be54f

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

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

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,23 +2351,27 @@ llvm::Triple SwiftASTContext::GetTriple() const {
23512351
return llvm::Triple(m_compiler_invocation_ap->getTargetTriple());
23522352
}
23532353

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;
23712375
}
23722376

23732377
bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
@@ -2385,18 +2389,15 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
23852389
}
23862390

23872391
const unsigned unspecified = 0;
2388-
std::string adjusted_triple = GetSwiftFriendlyTriple(triple);
2392+
llvm::Triple adjusted_triple = GetSwiftFriendlyTriple(triple);
23892393
// If the OS version is unspecified, do fancy things.
23902394
if (triple.getOSMajorVersion() == unspecified) {
23912395
// If a triple is "<arch>-apple-darwin" change it to be
23922396
// "<arch>-apple-macosx" otherwise the major and minor OS
23932397
// version we append below would be wrong.
23942398
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);
24002401

24012402
// Append the min OS to the triple if we have a target
24022403
ModuleSP module_sp;
@@ -2411,12 +2412,9 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
24112412

24122413
if (module) {
24132414
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());
24202418
}
24212419
}
24222420
if (llvm::Triple(triple).getOS() == llvm::Triple::UnknownOS) {
@@ -2425,15 +2423,14 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
24252423
return false;
24262424
}
24272425
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());
24292427

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);
24322429

2433-
assert(GetTriple() == adjusted_llvm_triple);
2430+
assert(GetTriple() == adjusted_triple);
24342431
assert(!m_ast_context_ap ||
24352432
(llvm::Triple(m_ast_context_ap->LangOpts.Target.getTriple()) ==
2436-
adjusted_llvm_triple));
2433+
adjusted_triple));
24372434

24382435
// Every time the triple is changed the LangOpts must be updated
24392436
// too, because Swift default-initializes the EnableObjCInterop

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ class SwiftASTContext : public TypeSystemSwift {
335335
bool SetTriple(const llvm::Triple triple,
336336
lldb_private::Module *module = nullptr);
337337

338+
/// Condition a triple to be safe for use with Swift. Swift is
339+
/// really peculiar about what CPU types it thinks it has standard
340+
/// libraries for.
341+
static llvm::Triple GetSwiftFriendlyTriple(llvm::Triple triple);
342+
338343
CompilerType GetCompilerType(swift::TypeBase *swift_type);
339344
CompilerType GetCompilerType(ConstString mangled_name);
340345
swift::Type GetSwiftType(CompilerType compiler_type);

lldb/unittests/Symbol/TestSwiftASTContext.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,18 @@ TEST_F(TestSwiftASTContext, IsNonTriviallyManagedReferenceType) {
199199
nullptr));
200200
#endif
201201
}
202+
203+
TEST_F(TestSwiftASTContext, SwiftFriendlyTriple) {
204+
EXPECT_EQ(SwiftASTContext::GetSwiftFriendlyTriple(
205+
llvm::Triple("x86_64-apple-macosx")),
206+
llvm::Triple("x86_64-apple-macosx"));
207+
EXPECT_EQ(SwiftASTContext::GetSwiftFriendlyTriple(
208+
llvm::Triple("x86_64h-apple-macosx")),
209+
llvm::Triple("x86_64-apple-macosx"));
210+
EXPECT_EQ(SwiftASTContext::GetSwiftFriendlyTriple(
211+
llvm::Triple("aarch64-apple-macosx")),
212+
llvm::Triple("arm64-apple-macosx"));
213+
EXPECT_EQ(SwiftASTContext::GetSwiftFriendlyTriple(
214+
llvm::Triple("aarch64_32-apple-watchos")),
215+
llvm::Triple("arm64_32-apple-watchos"));
216+
}

0 commit comments

Comments
 (0)