[clang] 3c1b423 - [clang] sort additional module maps when serializing

Richard Howell via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 12 12:00:52 PDT 2022


Author: Richard Howell
Date: 2022-09-12T12:00:43-07:00
New Revision: 3c1b42347b3a0666c93948ade2f420a20e060c1a

URL: https://github.com/llvm/llvm-project/commit/3c1b42347b3a0666c93948ade2f420a20e060c1a
DIFF: https://github.com/llvm/llvm-project/commit/3c1b42347b3a0666c93948ade2f420a20e060c1a.diff

LOG: [clang] sort additional module maps when serializing

Sort additional module maps when serializing pcm files. This ensures
the `MODULE_MAP_FILE` record is deterministic across repeated builds.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D133611

Added: 
    

Modified: 
    clang/lib/Serialization/ASTWriter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 1e835a4c68531..838c6e306cfb0 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1282,7 +1282,12 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
     if (auto *AdditionalModMaps =
             Map.getAdditionalModuleMapFiles(WritingModule)) {
       Record.push_back(AdditionalModMaps->size());
-      for (const FileEntry *F : *AdditionalModMaps)
+      SmallVector<const FileEntry *, 1> ModMaps(AdditionalModMaps->begin(),
+                                                AdditionalModMaps->end());
+      llvm::sort(ModMaps, [](const FileEntry *A, const FileEntry *B) {
+        return A->getName() < B->getName();
+      });
+      for (const FileEntry *F : ModMaps)
         AddPath(F->getName(), Record);
     } else {
       Record.push_back(0);


        


More information about the cfe-commits mailing list