From: Chandler Carruth Date: Fri, 27 Mar 2015 00:31:20 +0000 (+0000) Subject: [Modules] Sort the file IDs prior to building the flattened array of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36ef61c991c956473b6fbe8b81b6c88ff6b96206;p=clang [Modules] Sort the file IDs prior to building the flattened array of DeclIDs so that in addition to be grouped by file, the order of these groups is stable. Found by inspection, no test case. Not sure this can be observed without a randomized seed for the hash table, but we shouldn't be relying on the hash table layout under any circumstances. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233339 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 655c9fd28b..990a565e50 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -2857,15 +2857,18 @@ void ASTWriter::WriteFileDeclIDsMap() { using namespace llvm; RecordData Record; + SmallVector, 64> SortedFileDeclIDs( + FileDeclIDs.begin(), FileDeclIDs.end()); + std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), + llvm::less_first()); + // Join the vectors of DeclIDs from all files. - SmallVector FileSortedIDs; - for (FileDeclIDsTy::iterator - FI = FileDeclIDs.begin(), FE = FileDeclIDs.end(); FI != FE; ++FI) { - DeclIDInFileInfo &Info = *FI->second; - Info.FirstDeclIndex = FileSortedIDs.size(); - for (LocDeclIDsTy::iterator - DI = Info.DeclIDs.begin(), DE = Info.DeclIDs.end(); DI != DE; ++DI) - FileSortedIDs.push_back(DI->second); + SmallVector FileGroupedDeclIDs; + for (auto &FileDeclEntry : SortedFileDeclIDs) { + DeclIDInFileInfo &Info = *FileDeclEntry.second; + Info.FirstDeclIndex = FileGroupedDeclIDs.size(); + for (auto &LocDeclEntry : Info.DeclIDs) + FileGroupedDeclIDs.push_back(LocDeclEntry.second); } BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); @@ -2874,8 +2877,8 @@ void ASTWriter::WriteFileDeclIDsMap() { Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); Record.push_back(FILE_SORTED_DECLS); - Record.push_back(FileSortedIDs.size()); - Stream.EmitRecordWithBlob(AbbrevCode, Record, data(FileSortedIDs)); + Record.push_back(FileGroupedDeclIDs.size()); + Stream.EmitRecordWithBlob(AbbrevCode, Record, data(FileGroupedDeclIDs)); } void ASTWriter::WriteComments() {