aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/FrontendAction.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/Frontend/FrontendAction.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/Frontend/FrontendAction.cpp')
-rw-r--r--clang/lib/Frontend/FrontendAction.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index 68b8232..45245f3 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -843,6 +843,21 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
if (!CI.InitializeSourceManager(Input))
return false;
+ if (CI.getLangOpts().CPlusPlusModules && Input.getKind().isHeaderUnit() &&
+ Input.getKind().isPreprocessed() && !usesPreprocessorOnly()) {
+ // We have an input filename like foo.iih, but we want to find the right
+ // module name (and original file, to build the map entry).
+ // Check if the first line specifies the original source file name with a
+ // linemarker.
+ std::string PresumedInputFile = std::string(getCurrentFileOrBufferName());
+ ReadOriginalFileName(CI, PresumedInputFile);
+ // Unless the user overrides this, the module name is the name by which the
+ // original file was known.
+ if (CI.getLangOpts().ModuleName.empty())
+ CI.getLangOpts().ModuleName = std::string(PresumedInputFile);
+ CI.getLangOpts().CurrentModule = CI.getLangOpts().ModuleName;
+ }
+
// For module map files, we first parse the module map and synthesize a
// "<module-includes>" buffer before more conventional processing.
if (Input.getKind().getFormat() == InputKind::ModuleMap) {