aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaModule.cpp
diff options
context:
space:
mode:
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