summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-11-30 05:23:00 +0000
committerDouglas Gregor <dgregor@apple.com>2010-11-30 05:23:00 +0000
commit936a5b44eea36a698946dde3b0a1e35b21244209 (patch)
treea765e3c9a8e1528c6ea204d48a6b9a39fff753e5 /clang/lib/Serialization
parentebd45a004d6a1cd6e2cebb36fbaf07fc612b0be6 (diff)
downloadbcm5719-llvm-936a5b44eea36a698946dde3b0a1e35b21244209.tar.gz
bcm5719-llvm-936a5b44eea36a698946dde3b0a1e35b21244209.zip
When loading a precompiled preamble, use the file ID of the
precompiled preamble as the "main" source file's file ID within the source manager. This makes compiling with a precompiled preamble produce the same source locations as when compiling without the precompiled preamble; prior to this change, we ended up with different file IDs for source locations within the precompiled preamble vs. those after the precompiled preamble, even for entities (e.g., preprocessing entities) in the same file. llvm-svn: 120390
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r--clang/lib/Serialization/ASTReader.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 86732484bcd..1cac948d032 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2239,6 +2239,18 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
if (DeserializationListener)
DeserializationListener->ReaderInitialized(this);
+ // If this AST file is a precompiled preamble, then set the main file ID of
+ // the source manager to the file source file from which the preamble was
+ // built. This is the only valid way to use a precompiled preamble.
+ if (Type == Preamble) {
+ SourceLocation Loc
+ = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1);
+ if (Loc.isValid()) {
+ std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc);
+ SourceMgr.SetPreambleFileID(Decomposed.first);
+ }
+ }
+
return Success;
}
OpenPOWER on IntegriCloud