Skip to content

Commit 3e56d23

Browse files
authored
Merge pull request swiftlang#40415 from nkcsgexi/84125071
Deserialization: ignore search paths pointing into the SDK.
2 parents 987d53e + 645a27f commit 3e56d23

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,15 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
165165
return error(status);
166166
}
167167

168-
for (const auto &searchPath : Core->SearchPaths) {
169-
ctx.addSearchPath(
168+
StringRef SDKPath = ctx.SearchPathOpts.SDKPath;
169+
if (SDKPath.empty() ||
170+
!Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath)) {
171+
for (const auto &searchPath : Core->SearchPaths) {
172+
ctx.addSearchPath(
170173
ctx.SearchPathOpts.SearchPathRemapper.remapPath(searchPath.Path),
171-
searchPath.IsFramework, searchPath.IsSystem);
174+
searchPath.IsFramework,
175+
searchPath.IsSystem);
176+
}
172177
}
173178

174179
auto clangImporter = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: VENDOR=apple
2+
// RUN: %empty-directory(%t)
3+
// RUN: %empty-directory(%t/mock-sdk/usr/lib/swift/SystemLibrary.swiftmodule)
4+
// RUN: %empty-directory(%t/secret)
5+
6+
// RUN: %target-swift-frontend -emit-module %S/../Inputs/empty.swift -o %t/secret/SecretLibrary.swiftmodule
7+
// RUN: %target-swift-frontend -emit-module %S/../Inputs/empty.swift -o %t/mock-sdk/usr/lib/swift/SystemLibrary.swiftmodule/%target-swiftmodule-name -module-name SystemLibrary -I %t/secret -serialize-debugging-options
8+
9+
// We pick up search paths from normal imports...
10+
// RUN: %target-swift-frontend -typecheck %s -I %t/mock-sdk/usr/lib/swift/
11+
12+
// ...but not from content in the SDK.
13+
// RUN: %target-swift-frontend -typecheck %s -sdk %t/mock-sdk -verify -show-diagnostics-after-fatal
14+
15+
import SystemLibrary
16+
import SecretLibrary // expected-error {{no such module 'SecretLibrary'}}

0 commit comments

Comments
 (0)