Skip to content

Commit 88deaff

Browse files
Merge pull request #7265 from adrian-prantl/113997661-exe-triple-5.9
Avoid instantiating SwiftASTContextForModule in get_executable_triple…
2 parents 993b2f7 + ca58189 commit 88deaff

File tree

4 files changed

+41
-80
lines changed

4 files changed

+41
-80
lines changed

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

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,19 +2064,6 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
20642064
return ModuleSP();
20652065
}
20662066

2067-
static SwiftASTContext *GetModuleSwiftASTContext(Module &module) {
2068-
auto type_system_or_err =
2069-
module.GetTypeSystemForLanguage(lldb::eLanguageTypeSwift);
2070-
if (!type_system_or_err) {
2071-
llvm::consumeError(type_system_or_err.takeError());
2072-
return {};
2073-
}
2074-
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwift>(type_system_or_err->get());
2075-
if (!ts)
2076-
return {};
2077-
return ts->GetSwiftASTContext();
2078-
}
2079-
20802067
/// Scan a newly added lldb::Module for Swift modules and report any errors in
20812068
/// its module SwiftASTContext to Target.
20822069
static void ProcessModule(
@@ -2313,10 +2300,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
23132300
auto get_executable_triple = [&]() -> llvm::Triple {
23142301
if (!exe_module_sp)
23152302
return {};
2316-
auto *exe_ast_ctx = GetModuleSwiftASTContext(*exe_module_sp);
2317-
if (!exe_ast_ctx)
2318-
return {};
2319-
return exe_ast_ctx->GetLanguageOptions().Target;
2303+
return exe_module_sp->GetArchitecture().GetTriple();
23202304
};
23212305

23222306
llvm::Triple computed_triple;
@@ -2399,25 +2383,22 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
23992383
const bool use_all_compiler_flags =
24002384
!got_serialized_options || target.GetUseAllCompilerFlags();
24012385

2402-
for (size_t mi = 0; mi != num_images; ++mi) {
2403-
std::vector<std::string> extra_clang_args;
2404-
ProcessModule(target.GetImages().GetModuleAtIndex(mi), m_description,
2405-
discover_implicit_search_paths, use_all_compiler_flags,
2406-
target, triple, plugin_search_options, module_search_paths,
2407-
framework_search_paths, extra_clang_args);
2408-
swift_ast_sp->AddExtraClangArgs(extra_clang_args);
2409-
}
2386+
for (ModuleSP module_sp : target.GetImages().Modules())
2387+
if (module_sp) {
2388+
std::vector<std::string> extra_clang_args;
2389+
ProcessModule(module_sp, m_description, discover_implicit_search_paths,
2390+
use_all_compiler_flags, target, triple,
2391+
plugin_search_options, module_search_paths,
2392+
framework_search_paths, extra_clang_args);
2393+
swift_ast_sp->AddExtraClangArgs(extra_clang_args);
2394+
}
24102395

2411-
FileSpecList target_module_paths = target.GetSwiftModuleSearchPaths();
2412-
for (size_t mi = 0, me = target_module_paths.GetSize(); mi != me; ++mi)
2413-
module_search_paths.push_back(
2414-
target_module_paths.GetFileSpecAtIndex(mi).GetPath());
2396+
for (const FileSpec &path : target.GetSwiftModuleSearchPaths())
2397+
module_search_paths.push_back(path.GetPath());
24152398

2416-
FileSpecList target_framework_paths = target.GetSwiftFrameworkSearchPaths();
2417-
for (size_t fi = 0, fe = target_framework_paths.GetSize(); fi != fe; ++fi)
2418-
framework_search_paths.push_back(
2419-
{target_framework_paths.GetFileSpecAtIndex(fi).GetPath(),
2420-
/*is_system*/ false});
2399+
for (const FileSpec &path : target.GetSwiftFrameworkSearchPaths())
2400+
framework_search_paths.push_back({path.GetPath(),
2401+
/*is_system*/ false});
24212402

24222403
// Now fold any extra options we were passed. This has to be done
24232404
// BEFORE the ClangImporter is made by calling GetClangImporter or
@@ -2437,6 +2418,11 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
24372418

24382419
swift_ast_sp->ApplyDiagnosticOptions();
24392420

2421+
// Apply source path remappings found in each module's dSYM.
2422+
for (ModuleSP module : target.GetImages().Modules())
2423+
if (module)
2424+
swift_ast_sp->RemapClangImporterOptions(module->GetSourceMappingList());
2425+
24402426
// Apply source path remappings found in the target settings.
24412427
swift_ast_sp->RemapClangImporterOptions(target.GetSourcePathMap());
24422428
swift_ast_sp->FilterClangImporterOptions(

lldb/test/API/lang/swift/clangimporter/Werror/TestSwiftStripWerror.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def setUp(self):
1717
@swiftTest
1818
def test(self):
1919
"""This tests that -Werror is removed from ClangImporter options by
20-
introducing two conflicting macro definitions in idfferent dylibs.
20+
introducing two conflicting macro definitions in different dylibs.
2121
"""
2222
self.build()
2323
target, _, _, _ = lldbutil.run_to_source_breakpoint(
@@ -26,17 +26,13 @@ def test(self):
2626

2727
# Turn on logging.
2828
log = self.getBuildArtifact("types.log")
29-
self.expect("log enable lldb types -f " + log)
29+
self.expect('log enable lldb types -f "%s"' % log)
3030

3131
self.expect("expression foo", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["42"])
32-
sanity = 0
33-
import io
34-
35-
logfile = io.open(log, "r", encoding="utf-8")
36-
for line in logfile:
37-
self.assertFalse("-Werror" in line)
38-
if "-DCONFLICT" in line:
39-
sanity += 1
40-
# We see -DCONFLICT twice in the expression context and once in each of
41-
# the two Module contexts.
42-
self.assertEqual(sanity, 2 + 2)
32+
self.filecheck('platform shell cat "%s"' % log, __file__)
33+
# CHECK-NOT: SwiftASTContextForExpressions{{.*}}-Werror
34+
# CHECK: SwiftASTContextForExpressions{{.*}}-DCONFLICT
35+
# CHECK-NOT: SwiftASTContextForExpressions{{.*}}-Werror
36+
# CHECK: SwiftASTContextForExpressions{{.*}}-DCONFLICT
37+
# CHECK-NOT: SwiftASTContextForExpressions{{.*}}-DCONFLICT
38+
# CHECK-NOT: SwiftASTContextForExpressions{{.*}}-Werror

lldb/test/API/lang/swift/clangimporter/config_macros/TestSwiftDedupMacros.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,15 @@ def testSwiftDebugMacros(self):
4747

4848
# Turn on logging.
4949
log = self.getBuildArtifact("types.log")
50-
self.expect("log enable lldb types -f " + log)
50+
self.expect('log enable lldb types -f ""%s"' % log)
5151

5252
self.expect("expression foo", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["42"])
53-
debug = 0
54-
space = 0
55-
ndebug = 0
56-
space_with_space = 0
57-
import io
58-
59-
logfile = io.open(log, "r", encoding="utf-8")
60-
for line in logfile:
61-
if "-DDEBUG=1" in line:
62-
debug += 1
63-
if "-DSPACE" in line:
64-
space += 1
65-
if " SPACE" in line:
66-
space_with_space += 1
67-
if "-UNDEBUG" in line:
68-
ndebug += 1
69-
# One extra in SwiftASTContextPerModule.
70-
self.assertEqual(debug, 3)
71-
self.assertEqual(space, 3)
72-
self.assertEqual(space_with_space, 0)
73-
self.assertEqual(ndebug, 3)
53+
self.filecheck('platform shell cat "%s"' % log, __file__)
54+
# CHECK: SwiftASTContextForExpressions{{.*}}-DDEBUG=1
55+
# CHECK: SwiftASTContextForExpressions{{.*}}-DSPACE
56+
# CHECK-NOT: {{ SPACE}}
57+
# CHECK: SwiftASTContextForExpressions{{.*}}-UNDEBUG
58+
# CHECK: SwiftASTContextForModule("libDylib{{.*}}-DDEBUG=1
59+
# CHECK: SwiftASTContextForModule("libDylib{{.*}}-DSPACE
60+
# CHECK-NOT: {{ SPACE}}
61+
# CHECK: SwiftASTContextForModule("libDylib{{.*}}-UNDEBUG

lldb/test/API/lang/swift/clangimporter/remap_sdk_path/TestSwiftRemapSDKPath.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,5 @@ def test(self):
2424
self.expect("expression 1", substrs=["1"])
2525

2626
# Scan through the types log.
27-
import io
28-
29-
logfile = io.open(log, "r", encoding="utf-8")
30-
found = 0
31-
for line in logfile:
32-
if line.startswith(
33-
' SwiftASTContextForModule("a.out")::RemapClangImporterOptions() -- remapped'
34-
):
35-
if "/LocalSDK/" in line:
36-
found += 1
37-
self.assertEqual(found, 1)
27+
self.filecheck('platform shell cat "%s"' % log, __file__)
28+
# CHECK: SwiftASTContextForExpressions::RemapClangImporterOptions() -- remapped{{.*}}/LocalSDK/

0 commit comments

Comments
 (0)