diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2022-03-02 20:18:10 +0000 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2022-03-27 09:38:06 +0100 |
commit | d9cea8d3a8fff86672174780312674871729578c (patch) | |
tree | 8327afd9c03d7d5cbf5a98dbccb22e72219857f8 /clang/lib/Sema/SemaModule.cpp | |
parent | 674d52e8ced27bf427b3ea2c763a566ca9b8212a (diff) | |
download | llvm-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.cpp | 14 |
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 |