From: Argyrios Kyrtzidis Date: Thu, 30 Sep 2010 16:53:50 +0000 (+0000) Subject: Support implicit includes when generating a PCH and allow the user to pass a -include... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=297c706f219701b4c9464cccf527f3fe833afc95;p=clang Support implicit includes when generating a PCH and allow the user to pass a -include on the command line following the PCH include. Fixes rdar://7382084. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115159 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 0443edb26a..d7636079a4 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -263,7 +263,36 @@ bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, llvm::SmallVector CmdLineLines; Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); - Right.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); + + // Pick out implicit #includes after the PCH and don't consider them for + // validation; we will insert them into SuggestedPredefines so that the + // preprocessor includes them. + std::string IncludesAfterPCH; + llvm::SmallVector AfterPCHLines; + Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); + for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { + if (AfterPCHLines[i].startswith("#include ")) { + IncludesAfterPCH += AfterPCHLines[i]; + IncludesAfterPCH += '\n'; + } else { + CmdLineLines.push_back(AfterPCHLines[i]); + } + } + + // Make sure we add the includes last into SuggestedPredefines before we + // exit this function. + struct AddIncludesRAII { + std::string &SuggestedPredefines; + std::string &IncludesAfterPCH; + + AddIncludesRAII(std::string &SuggestedPredefines, + std::string &IncludesAfterPCH) + : SuggestedPredefines(SuggestedPredefines), + IncludesAfterPCH(IncludesAfterPCH) { } + ~AddIncludesRAII() { + SuggestedPredefines += IncludesAfterPCH; + } + } AddIncludes(SuggestedPredefines, IncludesAfterPCH); // Sort both sets of predefined buffer lines, since we allow some extra // definitions and they may appear at any point in the output. @@ -281,6 +310,11 @@ bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, bool ConflictingDefines = false; for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { llvm::StringRef Missing = MissingPredefines[I]; + if (Missing.startswith("#include ")) { + // An -include was specified when generating the PCH; it is included in + // the PCH, just ignore it. + continue; + } if (!Missing.startswith("#define ")) { Reader.Diag(diag::warn_pch_compiler_options_mismatch); return true;