[cfe-commits] r115159 - /cfe/trunk/lib/Serialization/ASTReader.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Sep 30 09:53:51 PDT 2010
Author: akirtzidis
Date: Thu Sep 30 11:53:50 2010
New Revision: 115159
URL: http://llvm.org/viewvc/llvm-project?rev=115159&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=115159&r1=115158&r2=115159&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Sep 30 11:53:50 2010
@@ -263,7 +263,36 @@
llvm::SmallVector<llvm::StringRef, 8> 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<llvm::StringRef, 8> 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 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;
More information about the cfe-commits
mailing list