aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/PCHReader.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-11-11 05:29:04 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-11-11 05:29:04 +0000
commit7b5a1210d93ca62ecd61800f245c87259b1f8f79 (patch)
treef2802e60f753a45d636a85d9a2875674a4c77329 /lib/Frontend/PCHReader.cpp
parent4d5936aaa4e4e2d41fe79101ac9c09444951448f (diff)
Redo how PCH handles its implicit include. Instead of treating this specially in
the front-end (as far as the preprocessor goes), follow the usual logic of inserting the (original include path) name into the predefines buffer. This pushes the responsibility for handling this to PCH instead of the front-end. In PCH this requires being a little more clever when we diff the predefines buffers. Neither of these solutions are particularly great, I think what we eventually should do is something like gcc where we insert a special marker to indicate the PCH file, but then run the preprocessor as usual. This would be clearer and would allow us to drop the overly clever predefines handling. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86806 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PCHReader.cpp')
-rw-r--r--lib/Frontend/PCHReader.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 42aa43b81f..936382482c 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -156,17 +156,34 @@ static std::vector<llvm::StringRef> splitLines(llvm::StringRef Str,
bool PCHValidator::ReadPredefinesBuffer(llvm::StringRef PCHPredef,
FileID PCHBufferID,
+ llvm::StringRef OriginalFileName,
std::string &SuggestedPredefines) {
- // If the two predefines buffers compare equal, we're done!
- if (PP.getPredefines() == PCHPredef)
+ // We are in the context of an implicit include, so the predefines buffer
+ // will have a #include entry for the PCH file itself. Find it and skip over
+ // it in the checking below.
+ llvm::SmallString<256> PCHInclude;
+ PCHInclude += "#include \"";
+ PCHInclude += OriginalFileName;
+ PCHInclude += "\"\n";
+ std::pair<llvm::StringRef,llvm::StringRef> Split =
+ llvm::StringRef(PP.getPredefines()).split(PCHInclude.str());
+ llvm::StringRef Left = Split.first, Right = Split.second;
+ assert(Left != PP.getPredefines() && "Missing PCH include entry!");
+
+ // If the predefines is equal to the joined left and right halves, we're done!
+ if (Left.size() + Right.size() == PCHPredef.size() &&
+ PCHPredef.startswith(Left) && PCHPredef.endswith(Right))
return false;
SourceManager &SourceMgr = PP.getSourceManager();
// The predefines buffers are different. Determine what the differences are,
// and whether they require us to reject the PCH file.
- std::vector<llvm::StringRef> CmdLineLines = splitLines(PP.getPredefines());
std::vector<llvm::StringRef> PCHLines = splitLines(PCHPredef);
+ std::vector<llvm::StringRef> CmdLineLines = splitLines(Left);
+ std::vector<llvm::StringRef> CmdLineLinesRight = splitLines(Right);
+ CmdLineLines.insert(CmdLineLines.end(),
+ CmdLineLinesRight.begin(), CmdLineLinesRight.end());
// Sort both sets of predefined buffer lines, since we allow some extra
// definitions and they may appear at any point in the output.
@@ -624,6 +641,7 @@ bool PCHReader::CheckPredefinesBuffer(llvm::StringRef PCHPredef,
FileID PCHBufferID) {
if (Listener)
return Listener->ReadPredefinesBuffer(PCHPredef, PCHBufferID,
+ ActualOriginalFileName,
SuggestedPredefines);
return false;
}
@@ -1333,7 +1351,8 @@ PCHReader::ReadPCHBlock() {
break;
case pch::ORIGINAL_FILE_NAME:
- OriginalFileName.assign(BlobStart, BlobLen);
+ ActualOriginalFileName.assign(BlobStart, BlobLen);
+ OriginalFileName = ActualOriginalFileName;
MaybeAddSystemRootToFilename(OriginalFileName);
break;