Skip to content

Commit e1f4daf

Browse files
authored
[clang][modules] Correctly set module map systemness (#131940)
This uses the systemness of the module map instead of of the Module instance, as doing otherwise could incorrectly parse the other modules in that module map as system. This is still correct as the only ways to get a system module are by the module map being in a system path, or the module having the [system] attribute, both of which are handled here. This makes it so that the systemness of a module is deterministic instead of depending on the path taken to build it.
1 parent 15c96d6 commit e1f4daf

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,10 +1360,17 @@ static bool compileModule(CompilerInstance &ImportingInstance,
13601360

13611361
StringRef ModuleMapFilePath = ModuleMapFile->getNameAsRequested();
13621362

1363+
// Use the systemness of the module map as parsed instead of using the
1364+
// IsSystem attribute of the module. If the module has [system] but the
1365+
// module map is not in a system path, then this would incorrectly parse
1366+
// any other modules in that module map as system too.
1367+
const SrcMgr::SLocEntry &SLoc = SourceMgr.getSLocEntry(ModuleMapFID);
1368+
bool IsSystem = isSystem(SLoc.getFile().getFileCharacteristic());
1369+
13631370
// Use the module map where this module resides.
13641371
Result = compileModuleImpl(
13651372
ImportingInstance, ImportLoc, Module->getTopLevelModuleName(),
1366-
FrontendInputFile(ModuleMapFilePath, IK, +Module->IsSystem),
1373+
FrontendInputFile(ModuleMapFilePath, IK, IsSystem),
13671374
ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName);
13681375
} else {
13691376
// FIXME: We only need to fake up an input file here as a way of
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
4+
// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
5+
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full -module-name=direct > %t/result1.json
6+
// RUN: rm -rf %t/cache
7+
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full -module-name=transitive > %t/result2.json
8+
// RUN: %deps-to-rsp %t/result1.json --module-name transitive > %t/1.rsp
9+
// RUN: %deps-to-rsp %t/result2.json --module-name transitive > %t/2.rsp
10+
// RUN: diff %t/1.rsp %t/2.rsp
11+
12+
//--- module.modulemap
13+
module direct [system] { header "direct.h" }
14+
module transitive { header "transitive.h" }
15+
16+
//--- direct.h
17+
#include "transitive.h"
18+
19+
//--- transitive.h
20+
// empty
21+
22+
//--- cdb.json.template
23+
[{
24+
"file": "",
25+
"directory": "DIR",
26+
"command": "clang -fmodules -fmodules-cache-path=DIR/cache -I DIR -x c"
27+
}]

0 commit comments

Comments
 (0)