Skip to content

[6.1] [cas] Definitions from unimported submodules should not be visible #9722

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
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
2 changes: 1 addition & 1 deletion clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3192,7 +3192,7 @@ bool ASTReader::isConsumerInterestedIn(Decl *D) {
// emitted when we import the relevant module.
if (isPartOfPerModuleInitializer(D)) {
auto *M = D->getImportedOwningModule();
if (M && M->Kind == Module::ModuleMapModule &&
if (M && M->isModuleMapModule() &&
getContext().DeclMustBeEmitted(D))
return false;
}
Expand Down
50 changes: 50 additions & 0 deletions clang/test/CAS/modules-include-tree-unimported-impl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Check that a definition for a symbol in an unimported submodule is not
// visible for codegen.

// REQUIRES: ondisk_cas

// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json

// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
// RUN: -cas-path %t/cas -module-files-dir %t/outputs \
// RUN: -format experimental-include-tree-full -mode preprocess-dependency-directives \
// RUN: > %t/deps.json

// RUN: %deps-to-rsp %t/deps.json --module Mod > %t/Mod.rsp
// RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp
// RUN: %clang @%t/Mod.rsp
// RUN: %clang @%t/tu.rsp -o - | FileCheck %s

// CHECK-NOT: @record = global
// CHECK: @record = external global

//--- cdb.json.template
[{
"file": "DIR/tu.c",
"directory": "DIR",
"command": "clang -S -emit-llvm DIR/tu.c -fmodules -fimplicit-modules -fimplicit-module-maps -fmodules-cache-path=DIR/module-cache"
}]

//--- module.modulemap
module Mod {
module A {
header "A.h"
}
explicit module B {
header "B.h"
}
}

//--- A.h
extern int record;

//--- B.h
int record = 7;

//--- tu.c
#include "A.h"
int tu(void) {
return record;
}