Skip to content

Commit 7e90960

Browse files
committed
[cas] Definitions from unimported submodules should not be visible
In 66228ed a merge conflict was incorrectly resolved leading to modules built with caching to expose definitions that come from unimported submodules to codegen. This would then cause linking errors if multiple TUs imported any part of that module. rdar://131028078 (cherry picked from commit e511172)
1 parent 086b115 commit 7e90960

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3192,7 +3192,7 @@ bool ASTReader::isConsumerInterestedIn(Decl *D) {
31923192
// emitted when we import the relevant module.
31933193
if (isPartOfPerModuleInitializer(D)) {
31943194
auto *M = D->getImportedOwningModule();
3195-
if (M && M->Kind == Module::ModuleMapModule &&
3195+
if (M && M->isModuleMapModule() &&
31963196
getContext().DeclMustBeEmitted(D))
31973197
return false;
31983198
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Check that a definition for a symbol in an unimported submodule is not
2+
// visible for codegen.
3+
4+
// REQUIRES: ondisk_cas
5+
6+
// RUN: rm -rf %t
7+
// RUN: split-file %s %t
8+
// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
9+
10+
// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
11+
// RUN: -cas-path %t/cas -module-files-dir %t/outputs \
12+
// RUN: -format experimental-include-tree-full -mode preprocess-dependency-directives \
13+
// RUN: > %t/deps.json
14+
15+
// RUN: %deps-to-rsp %t/deps.json --module Mod > %t/Mod.rsp
16+
// RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp
17+
// RUN: %clang @%t/Mod.rsp
18+
// RUN: %clang @%t/tu.rsp -o - | FileCheck %s
19+
20+
// CHECK-NOT: @record = global
21+
// CHECK: @record = external global
22+
23+
//--- cdb.json.template
24+
[{
25+
"file": "DIR/tu.c",
26+
"directory": "DIR",
27+
"command": "clang -S -emit-llvm DIR/tu.c -fmodules -fimplicit-modules -fimplicit-module-maps -fmodules-cache-path=DIR/module-cache"
28+
}]
29+
30+
//--- module.modulemap
31+
module Mod {
32+
module A {
33+
header "A.h"
34+
}
35+
explicit module B {
36+
header "B.h"
37+
}
38+
}
39+
40+
//--- A.h
41+
extern int record;
42+
43+
//--- B.h
44+
int record = 7;
45+
46+
//--- tu.c
47+
#include "A.h"
48+
int tu(void) {
49+
return record;
50+
}

0 commit comments

Comments
 (0)