diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 066261c0215b..6c5338a2dd52 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(SourceMgr)); Context.Comments.addDeserializedComments(Comments); } }