Skip to content

Commit 960542b

Browse files
committed
[clang][modules] Correctly set module map systemness (llvm#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. Fixes rdar://144798054 (cherry picked from commit e1f4daf)
1 parent 42e6d99 commit 960542b

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
@@ -1509,10 +1509,17 @@ static bool compileModule(CompilerInstance &ImportingInstance,
15091509

15101510
StringRef ModuleMapFilePath = ModuleMapFile->getNameAsRequested();
15111511

1512+
// Use the systemness of the module map as parsed instead of using the
1513+
// IsSystem attribute of the module. If the module has [system] but the
1514+
// module map is not in a system path, then this would incorrectly parse
1515+
// any other modules in that module map as system too.
1516+
const SrcMgr::SLocEntry &SLoc = SourceMgr.getSLocEntry(ModuleMapFID);
1517+
bool IsSystem = isSystem(SLoc.getFile().getFileCharacteristic());
1518+
15121519
// Use the module map where this module resides.
15131520
Result = compileModuleImpl(
15141521
ImportingInstance, ImportLoc, Module->getTopLevelModuleName(),
1515-
FrontendInputFile(ModuleMapFilePath, IK, +Module->IsSystem),
1522+
FrontendInputFile(ModuleMapFilePath, IK, IsSystem),
15161523
ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName);
15171524
} else {
15181525
// 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)