diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-11-30 05:23:00 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-11-30 05:23:00 +0000 |
commit | 414cb64f09ce48a36377458ce5e5a90c3ad41d00 (patch) | |
tree | 2eedb57943c956169c8e3a24eef7879afabb884e /lib/Serialization/ASTReader.cpp | |
parent | 15d5c83ce698a6b6ae1166f9008c6ead34ae7a5d (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120390 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTReader.cpp')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 86732484bc..1cac948d03 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/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; } |