diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-09-30 16:53:50 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-09-30 16:53:50 +0000 |
| commit | 58c65410ac3a05f2fea718e017b4b42fe6b15601 (patch) | |
| tree | 49e75433800c44f6b401157bc7a60597832b8533 /clang/lib/Serialization | |
| parent | 2f23b414e9bc3005098b6379af36933896c58315 (diff) | |
| download | bcm5719-llvm-58c65410ac3a05f2fea718e017b4b42fe6b15601.tar.gz bcm5719-llvm-58c65410ac3a05f2fea718e017b4b42fe6b15601.zip | |
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.
llvm-svn: 115159
Diffstat (limited to 'clang/lib/Serialization')
| -rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 0443edb26af..d7636079a46 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -263,7 +263,36 @@ bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, 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 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; |

