Skip to content

Only scan Swift compile units when scanning for the Swift SDK #3206

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 1 commit into from
Aug 26, 2021
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
8 changes: 5 additions & 3 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1769,9 +1769,11 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
// Force parsing of the CUs to extract the SDK info.
XcodeSDK sdk;
if (SymbolFile *sym_file = module.GetSymbolFile())
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i)
sdk.Merge(
sym_file->ParseXcodeSDK(*sym_file->GetCompileUnitAtIndex(i)));
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) {
auto &cu = *sym_file->GetCompileUnitAtIndex(i);
if (cu.GetLanguage() == lldb::eLanguageTypeSwift)
sdk.Merge(sym_file->ParseXcodeSDK(cu));
}

std::string sdk_path = HostInfo::GetXcodeSDKPath(sdk).str();
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Host SDK path for sdk %s is %s.",
Expand Down
9 changes: 9 additions & 0 deletions lldb/test/API/lang/swift/xcode_sdk/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS := -Xfrontend -no-serialize-debugging-options
SWIFT_BRIDGING_HEADER := bridging-header.h
LD_EXTRAS := ignored.o

all: ignored.o $(EXE)

# Artificially inject a wrong SDK into a C file to test that it is ebing ignored.
ignored.o: ignored.c
$(CC) -target $(ARCH)-apple-macos -c $< -o $@ \
-isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path)

include Makefile.rules
2 changes: 1 addition & 1 deletion lldb/test/API/lang/swift/xcode_sdk/TestSwiftXcodeSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_decode(self):
lldbutil.run_to_name_breakpoint(self, 'main')

self.expect("p 1")
self.check_log(log, ".sdk")
self.check_log(log, "MacOSX")

@swiftTest
@skipUnlessDarwin
Expand Down
1 change: 1 addition & 0 deletions lldb/test/API/lang/swift/xcode_sdk/bridging-header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void c_function();
1 change: 1 addition & 0 deletions lldb/test/API/lang/swift/xcode_sdk/ignored.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void c_function() {}
1 change: 1 addition & 0 deletions lldb/test/API/lang/swift/xcode_sdk/main.swift
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
c_function()
print("I have loaded Swift successfully - break here")