diff options
author | Michael Spencer <bigcheesegs@gmail.com> | 2025-03-19 11:19:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-19 11:19:25 -0700 |
commit | e1f4daf836e24d9c39fdd4fda84c01e4af31fd65 (patch) | |
tree | 61575989c4020b29c830dc1534aa83db1711a730 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 15c96d6874e8e37e583cf2994b290b9a6869cd30 (diff) | |
download | llvm-e1f4daf836e24d9c39fdd4fda84c01e4af31fd65.zip llvm-e1f4daf836e24d9c39fdd4fda84c01e4af31fd65.tar.gz llvm-e1f4daf836e24d9c39fdd4fda84c01e4af31fd65.tar.bz2 |
[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.
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 5709e7a..02994bce 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1360,10 +1360,17 @@ static bool compileModule(CompilerInstance &ImportingInstance, StringRef ModuleMapFilePath = ModuleMapFile->getNameAsRequested(); + // Use the systemness of the module map as parsed instead of using the + // IsSystem attribute of the module. If the module has [system] but the + // module map is not in a system path, then this would incorrectly parse + // any other modules in that module map as system too. + const SrcMgr::SLocEntry &SLoc = SourceMgr.getSLocEntry(ModuleMapFID); + bool IsSystem = isSystem(SLoc.getFile().getFileCharacteristic()); + // Use the module map where this module resides. Result = compileModuleImpl( ImportingInstance, ImportLoc, Module->getTopLevelModuleName(), - FrontendInputFile(ModuleMapFilePath, IK, +Module->IsSystem), + FrontendInputFile(ModuleMapFilePath, IK, IsSystem), ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName); } else { // FIXME: We only need to fake up an input file here as a way of |