@@ -914,8 +914,7 @@ SwiftASTContext::SwiftASTContext() {
914
914
}
915
915
#endif
916
916
917
- SwiftASTContext::SwiftASTContext (std::string description, llvm::Triple triple,
918
- Target *target)
917
+ SwiftASTContext::SwiftASTContext (std::string description, Target *target)
919
918
: TypeSystemSwift(),
920
919
m_compiler_invocation_ap(new swift::CompilerInvocation()) {
921
920
m_description = description;
@@ -935,7 +934,6 @@ SwiftASTContext::SwiftASTContext(std::string description, llvm::Triple triple,
935
934
if (target)
936
935
m_target_wp = target->shared_from_this ();
937
936
938
- SetTriple (triple);
939
937
swift::IRGenOptions &ir_gen_opts =
940
938
m_compiler_invocation_ap->getIRGenOptions ();
941
939
ir_gen_opts.OutputKind = swift::IRGenOutputKind::Module;
@@ -1715,9 +1713,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
1715
1713
fallback ? static_cast <SwiftASTContext *>(
1716
1714
new SwiftASTContextForExpressions (m_description, *target))
1717
1715
: static_cast <SwiftASTContext *>(new SwiftASTContextForModule (
1718
- *typeref_typesystem, m_description,
1719
- target ? target->GetArchitecture ().GetTriple () : triple,
1720
- target)));
1716
+ *typeref_typesystem, m_description, target)));
1721
1717
bool suppress_config_log = false ;
1722
1718
auto defer_log = llvm::make_scope_exit ([swift_ast_sp, &suppress_config_log] {
1723
1719
// To avoid spamming the log with useless info, we don't log the
@@ -1734,12 +1730,8 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
1734
1730
swift_ast_sp->GetLanguageOptions ().EnableAccessControl = false ;
1735
1731
swift_ast_sp->GetLanguageOptions ().EnableTargetOSChecking = false ;
1736
1732
1737
- swift_ast_sp->SetTriple (triple, &module );
1738
-
1739
- bool set_triple = false ;
1740
1733
bool found_swift_modules = false ;
1741
1734
SymbolFile *sym_file = module .GetSymbolFile ();
1742
- std::string target_triple;
1743
1735
1744
1736
if (sym_file) {
1745
1737
bool got_serialized_options = false ;
@@ -1752,17 +1744,11 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
1752
1744
swift_ast_sp->m_module_import_warnings .push_back (std::string (error));
1753
1745
}
1754
1746
1755
- // Some of the bits in the compiler options we keep separately, so
1756
- // we need to populate them from the serialized options:
1757
1747
llvm::StringRef serialized_triple =
1758
1748
swift_ast_sp->GetCompilerInvocation ().getTargetTriple ();
1759
- if (serialized_triple.empty ()) {
1760
- LOG_PRINTF (LIBLLDB_LOG_TYPES, " Serialized triple was empty." );
1761
- } else {
1762
- LOG_PRINTF (LIBLLDB_LOG_TYPES, " Found serialized triple %s." ,
1749
+ if (!serialized_triple.empty ()) {
1750
+ LOG_PRINTF (LIBLLDB_LOG_TYPES, " Serialized/default triple would have been %s." ,
1763
1751
serialized_triple.str ().c_str ());
1764
- swift_ast_sp->SetTriple (llvm::Triple (serialized_triple), &module );
1765
- set_triple = true ;
1766
1752
}
1767
1753
1768
1754
// SDK path setup.
@@ -1802,24 +1788,12 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
1802
1788
}
1803
1789
}
1804
1790
1805
- if (!set_triple) {
1806
- llvm::Triple llvm_triple = swift_ast_sp->GetTriple ();
1807
-
1808
- // LLVM wants this to be set to iOS or MacOSX; if we're working on
1809
- // a bare-boards type image, change the triple for LLVM's benefit.
1810
- if (llvm_triple.getVendor () == llvm::Triple::Apple &&
1811
- llvm_triple.getOS () == llvm::Triple::UnknownOS) {
1812
- if (llvm_triple.getArch () == llvm::Triple::arm ||
1813
- llvm_triple.getArch () == llvm::Triple::thumb) {
1814
- llvm_triple.setOS (llvm::Triple::IOS);
1815
- } else {
1816
- llvm_triple.setOS (llvm::Triple::MacOSX);
1817
- }
1818
- swift_ast_sp->SetTriple (llvm_triple, &module );
1819
- }
1820
- }
1791
+ // The serialized triple is the triple of the last binary
1792
+ // __swiftast section that was processed. Instead of relying on
1793
+ // the section contents order, we overwrite the triple in the
1794
+ // CompilerInvocation with the triple recovered from the binary.
1795
+ swift_ast_sp->SetTriple (triple, &module );
1821
1796
1822
- triple = swift_ast_sp->GetTriple ();
1823
1797
std::string resource_dir = swift_ast_sp->GetResourceDir (triple);
1824
1798
ConfigureResourceDirs (swift_ast_sp->GetCompilerInvocation (),
1825
1799
FileSpec (resource_dir), triple);
@@ -8287,8 +8261,7 @@ SwiftASTContext::GetASTVectorForModule(const Module *module) {
8287
8261
8288
8262
SwiftASTContextForExpressions::SwiftASTContextForExpressions (
8289
8263
std::string description, Target &target)
8290
- : SwiftASTContext(std::move(description),
8291
- target.GetArchitecture().GetTriple(), &target),
8264
+ : SwiftASTContext(std::move(description), &target),
8292
8265
m_typeref_typesystem(*this ),
8293
8266
m_persistent_state_up(new SwiftPersistentExpressionState) {}
8294
8267
0 commit comments