Skip to content

Commit e511172

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
1 parent 7004047 commit e511172

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
@@ -3205,7 +3205,7 @@ bool ASTReader::isConsumerInterestedIn(Decl *D) {
32053205
// emitted when we import the relevant module.
32063206
if (isPartOfPerModuleInitializer(D)) {
32073207
auto *M = D->getImportedOwningModule();
3208-
if (M && M->Kind == Module::ModuleMapModule &&
3208+
if (M && M->isModuleMapModule() &&
32093209
getContext().DeclMustBeEmitted(D))
32103210
return false;
32113211
}
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)