aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaModule.cpp
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2022-03-02 20:18:10 +0000
committerIain Sandoe <iain@sandoe.co.uk>2022-03-27 09:38:06 +0100
commitd9cea8d3a8fff86672174780312674871729578c (patch)
tree8327afd9c03d7d5cbf5a98dbccb22e72219857f8 /clang/lib/Sema/SemaModule.cpp
parent674d52e8ced27bf427b3ea2c763a566ca9b8212a (diff)
downloadllvm-d9cea8d3a8fff86672174780312674871729578c.zip
llvm-d9cea8d3a8fff86672174780312674871729578c.tar.gz
llvm-d9cea8d3a8fff86672174780312674871729578c.tar.bz2
[C++20][Modules][HU 4/5] Handle pre-processed header units.
We wish to support emitting a pre-processed output for an importable header unit, that can be consumed to produce the same header units as the original source. This means that ee need to find the original filename used to produce the re-preprocessed output, so that it can be assigned as the module name. This is peeked from the first line of the pre-processed source when the action sets up the files. Differential Revision: https://reviews.llvm.org/D121098
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r--clang/lib/Sema/SemaModule.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index e28de8c..893b913 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -109,10 +109,18 @@ void Sema::HandleStartOfHeaderUnit() {
const_cast<LangOptions &>(getLangOpts()).CurrentModule = HUName.str();
}
- auto &Map = PP.getHeaderSearchInfo().getModuleMap();
// TODO: Make the C++20 header lookup independent.
- Module::Header H{getLangOpts().CurrentModule, getLangOpts().CurrentModule,
- SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())};
+ // When the input is pre-processed source, we need a file ref to the original
+ // file for the header map.
+ auto F = SourceMgr.getFileManager().getFile(HUName);
+ // For the sake of error recovery (if someone has moved the original header
+ // after creating the pre-processed output) fall back to obtaining the file
+ // ref for the input file, which must be present.
+ if (!F)
+ F = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
+ assert(F && "failed to find the header unit source?");
+ Module::Header H{HUName.str(), HUName.str(), *F};
+ auto &Map = PP.getHeaderSearchInfo().getModuleMap();
Module *Mod = Map.createHeaderUnit(StartOfTU, HUName, H);
assert(Mod && "module creation should not fail");
ModuleScopes.push_back({}); // No GMF