Skip to content

Commit ce00aef

Browse files
[Modules] Avoid false swift module sharing
When the swiftmodule is built with different clang importer arguments, they can have the same module hash, causing them to be wrongly re-used even they contains different interfaces. Add ReducedExtraArgs to the module hash to disambiguate them. rdar://131408266 (cherry picked from commit d3adf17)
1 parent a9abcb6 commit ce00aef

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,8 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
20352035
auto normalizedTargetTriple =
20362036
getTargetSpecificModuleTriple(genericSubInvocation.getLangOptions().Target);
20372037
std::string sdkBuildVersion = getSDKBuildVersion(sdkPath);
2038+
const auto ExtraArgs = genericSubInvocation.getClangImporterOptions()
2039+
.getReducedExtraArgsForSwiftModuleDependency();
20382040

20392041
llvm::hash_code H = hash_combine(
20402042
// Start with the compiler version (which will be either tag names or
@@ -2076,6 +2078,10 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
20762078
// correctly load the dependencies.
20772079
genericSubInvocation.getCASOptions().getModuleScanningHashComponents(),
20782080

2081+
// Clang ExtraArgs that affects how clang types are imported into swift
2082+
// module.
2083+
llvm::hash_combine_range(ExtraArgs.begin(), ExtraArgs.end()),
2084+
20792085
// Whether or not OSSA modules are enabled.
20802086
//
20812087
// If OSSA modules are enabled, we use a separate namespace of modules to
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test %t/main-1.swift -module-cache-path %t/clang-module-cache \
5+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -O \
6+
// RUN: -o %t/deps-1.json -I %t/include
7+
8+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test %t/main-2.swift -module-cache-path %t/clang-module-cache \
9+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -O \
10+
// RUN: -o %t/deps-2.json -Xcc -DHAS_FOO=1 -I %t/include
11+
12+
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps-1.json Library modulePath > %t/path-1
13+
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps-2.json Library modulePath > %t/path-2
14+
15+
/// Library module should not have the same path.
16+
// RUN: not diff %t/path-1 %t/path-2
17+
18+
//--- main-1.swift
19+
import Library
20+
func test() {
21+
bar();
22+
}
23+
24+
//--- main-2.swift
25+
import Library
26+
func test() {
27+
foo();
28+
}
29+
30+
//--- include/Library.swiftinterface
31+
// swift-interface-format-version: 1.0
32+
// swift-module-flags: -module-name Library -O -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -user-module-version 1.0
33+
@_exported import A
34+
public func test() {}
35+
36+
//--- include/a.h
37+
#ifdef HAS_FOO
38+
void foo(void);
39+
#endif
40+
void bar(void);
41+
42+
//--- include/module.modulemap
43+
module A {
44+
header "a.h"
45+
export *
46+
}

0 commit comments

Comments
 (0)