diff options
author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2016-12-19 21:06:06 +0000 |
---|---|---|
committer | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2016-12-19 21:06:06 +0000 |
commit | c23af5707d40f0a4a6870b641b4128050435e3a8 (patch) | |
tree | 8dc892ce3b5b3ab1ceacdb579f50d8e34caa5a72 /clang/lib/Serialization/ASTReader.cpp | |
parent | 20565e2aa1c63caa9a2cab07da6b71e81f438d46 (diff) | |
download | bcm5719-llvm-c23af5707d40f0a4a6870b641b4128050435e3a8.tar.gz bcm5719-llvm-c23af5707d40f0a4a6870b641b4128050435e3a8.zip |
[ASTReader] Sort RawComments before merging
`RawComments` are sorted by comparing underlying `SourceLocation`'s. This is
done by comparing `FileID` and `Offset`; when the `FileID` is the same it means
the locations are within the same TU and the `Offset` is used.
FileID, from the source code: "A mostly-opaque identifier, where 0 is
"invalid", >0 is this module, and <-1 is something loaded from another
module.". That said, when de-serializing SourceLocations, FileID's from
RawComments loaded from other modules get negative IDs where previously they
were positive. This makes imported RawComments unsorted, leading to a wrong
merge with other comments from the current TU. Fix that by sorting RawComments
properly after de-serialization and before merge.
This fixes an assertion in `ASTContext::getRawCommentForDeclNoCache`,
which fires only in a debug build of clang.
Differential Revision: https://reviews.llvm.org/D27546
rdar://problem/29287314
llvm-svn: 290134
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 066261c0215..6c5338a2dd5 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -8471,6 +8471,10 @@ void ASTReader::ReadComments() { } } NextCursor: + // De-serialized SourceLocations get negative FileIDs for other modules, + // potentially invalidating the original order. Sort it again. + std::sort(Comments.begin(), Comments.end(), + BeforeThanCompare<RawComment>(SourceMgr)); Context.Comments.addDeserializedComments(Comments); } } |