diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2023-08-10 10:11:42 -0700 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2023-08-10 10:11:43 -0700 |
commit | bbdb0c7e4496b145a5e9354f951eec272695049d (patch) | |
tree | 3b1654b670578d0fef9222bfb4e886bb77195123 /clang/lib/Lex/ModuleMap.cpp | |
parent | 89fa0dd1fb25698270e9382a94929d2f5747e802 (diff) | |
download | llvm-bbdb0c7e4496b145a5e9354f951eec272695049d.zip llvm-bbdb0c7e4496b145a5e9354f951eec272695049d.tar.gz llvm-bbdb0c7e4496b145a5e9354f951eec272695049d.tar.bz2 |
[clang][modules] Respect "-fmodule-name=" when serializing included files into a PCH
Clang writes the set of textually included files into AST files, so that importers know to avoid including those files again and instead deserialize their contents from the AST on-demand.
Logic for determining the set of included files files only considers headers that are either non-modular or that are modular but with `HeaderFileInfo::isCompilingModuleHeader` set. Logic for computing that bit is different than the one that determines whether to include a header textually with the "-fmodule-name=Mod" option. That can lead to header from module "Mod" being included textually in a PCH, but be omitted in the serialized set of included files. This can then allow such header to be textually included from importer of the PCH, wreaking havoc.
This patch fixes that by aligning the logic for computing `HeaderFileInfo::isCompilingModuleHeader` with the logic for deciding whether to include modular header textually.
As far as I can tell, this bug has been in Clang for forever. It got accidentally "fixed" by D114095 (that changed the logic for determining the set of included files) and got broken again in D155131 (which is essentially a revert of the former).
rdar://113520515
Reviewed By: benlangmuir
Differential Revision: https://reviews.llvm.org/D157559
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 5a1b0a9..f8b767e 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1268,8 +1268,7 @@ void ModuleMap::addHeader(Module *Mod, Module::Header Header, HeaderList.push_back(KH); Mod->Headers[headerRoleToKind(Role)].push_back(Header); - bool isCompilingModuleHeader = - LangOpts.isCompilingModule() && Mod->getTopLevelModule() == SourceModule; + bool isCompilingModuleHeader = Mod->isForBuilding(LangOpts); if (!Imported || isCompilingModuleHeader) { // When we import HeaderFileInfo, the external source is expected to // set the isModuleHeader flag itself. |