Skip to content

Commit 404777d

Browse files
committed
Only scan Swift compile units when scanning for the Swift SDK
While generally being a sensibli thing to do, this works around an edge case where system C libraries that were compiled against a different SDK are messing up the Swift SDK configuration. rdar://76071920
1 parent c967070 commit 404777d

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,9 +1769,11 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
17691769
// Force parsing of the CUs to extract the SDK info.
17701770
XcodeSDK sdk;
17711771
if (SymbolFile *sym_file = module.GetSymbolFile())
1772-
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i)
1773-
sdk.Merge(
1774-
sym_file->ParseXcodeSDK(*sym_file->GetCompileUnitAtIndex(i)));
1772+
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) {
1773+
auto &cu = *sym_file->GetCompileUnitAtIndex(i);
1774+
if (cu.GetLanguage() == lldb::eLanguageTypeSwift)
1775+
sdk.Merge(sym_file->ParseXcodeSDK(cu));
1776+
}
17751777

17761778
std::string sdk_path = HostInfo::GetXcodeSDKPath(sdk).str();
17771779
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Host SDK path for sdk %s is %s.",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
SWIFT_SOURCES := main.swift
22
SWIFTFLAGS_EXTRAS := -Xfrontend -no-serialize-debugging-options
3+
SWIFT_BRIDGING_HEADER := bridging-header.h
4+
LD_EXTRAS := ignored.o
5+
6+
all: ignored.o $(EXE)
7+
8+
# Artificially inject a wrong SDK into a C file to test that it is ebing ignored.
9+
ignored.o: ignored.c
10+
$(CC) -target $(ARCH)-apple-macos -c $< -o $@ \
11+
-isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path)
312

413
include Makefile.rules

lldb/test/API/lang/swift/xcode_sdk/TestSwiftXcodeSDK.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_decode(self):
3535
lldbutil.run_to_name_breakpoint(self, 'main')
3636

3737
self.expect("p 1")
38-
self.check_log(log, ".sdk")
38+
self.check_log(log, "MacOSX")
3939

4040
@swiftTest
4141
@skipUnlessDarwin
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void c_function();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void c_function() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
c_function()
12
print("I have loaded Swift successfully - break here")

0 commit comments

Comments
 (0)