Skip to content

66802226 5.3 #1629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lldb/include/lldb/Symbol/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ class SwiftASTContext : public TypeSystemSwift {
bool SetTriple(const llvm::Triple triple,
lldb_private::Module *module = nullptr);

/// Condition a triple to be safe for use with Swift. Swift is
/// really peculiar about what CPU types it thinks it has standard
/// libraries for.
static llvm::Triple GetSwiftFriendlyTriple(llvm::Triple triple);

CompilerType GetCompilerType(swift::TypeBase *swift_type);
CompilerType GetCompilerType(ConstString mangled_name);
swift::Type GetSwiftType(CompilerType compiler_type);
Expand Down
45 changes: 22 additions & 23 deletions lldb/source/Symbol/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,14 +2319,20 @@ llvm::Triple SwiftASTContext::GetTriple() const {
return llvm::Triple(m_compiler_invocation_ap->getTargetTriple());
}

/// Conditions a triple string to be safe for use with Swift. Right
/// now this just strips the Haswell marker off the CPU name.
/// Conditions a triple string to be safe for use with Swift. Swift
/// is really peculiar about what CPU types it thinks it has standard
/// libraries for.
///
/// TODO: Make Swift more robust.
static std::string GetSwiftFriendlyTriple(StringRef triple) {
if (triple.consume_front("x86_64h"))
return std::string("x86_64") + triple.str();
return triple.str();
llvm::Triple SwiftASTContext::GetSwiftFriendlyTriple(llvm::Triple triple) {
StringRef arch_name = triple.getArchName();
if (arch_name == "x86_64h")
triple.setArchName("x86_64");
else if (arch_name == "aarch64")
triple.setArchName("arm64");
else if (arch_name == "aarch64_32")
triple.setArchName("arm64_32");
return triple;
}

bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
Expand All @@ -2344,18 +2350,15 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
}

const unsigned unspecified = 0;
std::string adjusted_triple = GetSwiftFriendlyTriple(triple.str());
llvm::Triple adjusted_triple = GetSwiftFriendlyTriple(triple);
// If the OS version is unspecified, do fancy things.
if (triple.getOSMajorVersion() == unspecified) {
// If a triple is "<arch>-apple-darwin" change it to be
// "<arch>-apple-macosx" otherwise the major and minor OS
// version we append below would be wrong.
if (triple.getVendor() == llvm::Triple::VendorType::Apple &&
triple.getOS() == llvm::Triple::OSType::Darwin) {
llvm::Triple mac_triple(adjusted_triple);
mac_triple.setOS(llvm::Triple::OSType::MacOSX);
adjusted_triple = mac_triple.str();
}
triple.getOS() == llvm::Triple::OSType::Darwin)
adjusted_triple.setOS(llvm::Triple::OSType::MacOSX);

// Append the min OS to the triple if we have a target
ModuleSP module_sp;
Expand All @@ -2370,12 +2373,9 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {

if (module) {
if (ObjectFile *objfile = module->GetObjectFile())
if (llvm::VersionTuple version = objfile->GetMinimumOSVersion()) {
llvm::Triple vers_triple(adjusted_triple);
vers_triple.setOSName(vers_triple.getOSName().str() +
version.getAsString());
adjusted_triple = vers_triple.str();
}
if (llvm::VersionTuple version = objfile->GetMinimumOSVersion())
adjusted_triple.setOSName(adjusted_triple.getOSName().str() +
version.getAsString());
}
}
if (llvm::Triple(triple).getOS() == llvm::Triple::UnknownOS) {
Expand All @@ -2384,15 +2384,14 @@ bool SwiftASTContext::SetTriple(const llvm::Triple triple, Module *module) {
return false;
}
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") setting to \"%s\"",
triple.str().c_str(), adjusted_triple.c_str());
triple.str().c_str(), adjusted_triple.str().c_str());

llvm::Triple adjusted_llvm_triple(adjusted_triple);
m_compiler_invocation_ap->setTargetTriple(adjusted_llvm_triple);
m_compiler_invocation_ap->setTargetTriple(adjusted_triple);

assert(GetTriple() == adjusted_llvm_triple);
assert(GetTriple() == adjusted_triple);
assert(!m_ast_context_ap ||
(llvm::Triple(m_ast_context_ap->LangOpts.Target.getTriple()) ==
adjusted_llvm_triple));
adjusted_triple));

// Every time the triple is changed the LangOpts must be updated
// too, because Swift default-initializes the EnableObjCInterop
Expand Down
15 changes: 15 additions & 0 deletions lldb/unittests/Symbol/TestSwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,18 @@ TEST_F(TestSwiftASTContext, IsNonTriviallyManagedReferenceType) {
nullptr));
#endif
}

TEST_F(TestSwiftASTContext, SwiftFriendlyTriple) {
EXPECT_EQ(SwiftASTContext::GetSwiftFriendlyTriple(
llvm::Triple("x86_64-apple-macosx")),
llvm::Triple("x86_64-apple-macosx"));
EXPECT_EQ(SwiftASTContext::GetSwiftFriendlyTriple(
llvm::Triple("x86_64h-apple-macosx")),
llvm::Triple("x86_64-apple-macosx"));
EXPECT_EQ(SwiftASTContext::GetSwiftFriendlyTriple(
llvm::Triple("aarch64-apple-macosx")),
llvm::Triple("arm64-apple-macosx"));
EXPECT_EQ(SwiftASTContext::GetSwiftFriendlyTriple(
llvm::Triple("aarch64_32-apple-watchos")),
llvm::Triple("arm64_32-apple-watchos"));
}