diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-12 01:31:05 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-12 01:31:05 +0000 |
commit | b64c19365deab788753d29c9bc881253c3f16f37 (patch) | |
tree | 904471327e615a25388412991745290bf92b668f /tools/clang-cc/clang-cc.cpp | |
parent | 06ab044127f0ff9a2b3696b6787d23c877505292 (diff) |
Make precompiled headers work with -E. When we're only preprocessing
(with -E), we turn the PCH include into an implicit include of the
file from which the PCH file was generated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71534 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-cc/clang-cc.cpp')
-rw-r--r-- | tools/clang-cc/clang-cc.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index ca8d6e5117..a948f843e4 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -1267,7 +1267,8 @@ void InitializePreprocessorInitOptions(PreprocessorInitOptions &InitOpts) for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i) InitOpts.addMacroInclude(ImplicitMacroIncludes[i]); - if (!ImplicitIncludePTH.empty() || !ImplicitIncludes.empty()) { + if (!ImplicitIncludePTH.empty() || !ImplicitIncludes.empty() || + (!ImplicitIncludePCH.empty() && ProgAction == PrintPreprocessedInput)) { // We want to add these paths to the predefines buffer in order, make a // temporary vector to sort by their occurrence. llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths; @@ -1275,6 +1276,9 @@ void InitializePreprocessorInitOptions(PreprocessorInitOptions &InitOpts) if (!ImplicitIncludePTH.empty()) OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(), &ImplicitIncludePTH)); + if (!ImplicitIncludePCH.empty() && ProgAction == PrintPreprocessedInput) + OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(), + &ImplicitIncludePCH)); for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i) OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i), &ImplicitIncludes[i])); @@ -1288,9 +1292,18 @@ void InitializePreprocessorInitOptions(PreprocessorInitOptions &InitOpts) Ptr >= &ImplicitIncludes[0] && Ptr <= &ImplicitIncludes[ImplicitIncludes.size()-1]) { InitOpts.addInclude(*Ptr, false); - } else { - assert(Ptr == &ImplicitIncludePTH); + } else if (Ptr == &ImplicitIncludePTH) { InitOpts.addInclude(*Ptr, true); + } else { + // We end up here when we're producing preprocessed output and + // we loaded a PCH file. In this case, just include the header + // file that was used to build the precompiled header. + assert(Ptr == &ImplicitIncludePCH); + std::string OriginalFile = PCHReader::getOriginalSourceFile(*Ptr); + if (!OriginalFile.empty()) { + InitOpts.addInclude(OriginalFile, false); + ImplicitIncludePCH.clear(); + } } } } |