Author: Chuanqi Xu
Date: 2025-03-26T16:01:08+08:00
New Revision: c41926013fd8b23c3d1eca51804a2de36c88433a

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

LOG: [Serialization] Avoid iterating Dense{Map,Set} to break determinism
in ASTWriter

It is bad to iterate Dense{Map,Set} in ASTWriter. Since the order in
Dense{Map, Set} is not stable. It may cause the produced BMI differ
even if we run the compiler twice without modifying any other thing.

Added: 
    

Modified: 
    clang/include/clang/Serialization/ASTWriter.h
    clang/lib/Serialization/ASTWriter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 6b5cc181e2e13..bdf3aca0637c8 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -370,7 +370,7 @@ class ASTWriter : public ASTDeserializationListener,
   ///
   /// Only meaningful for standard C++ named modules. See the comments in
   /// createSignatureForNamedModule() for details.
-  llvm::DenseSet<Module *> TouchedTopLevelModules;
+  llvm::SetVector<Module *> TouchedTopLevelModules;
 
   /// An update to a Decl.
   class DeclUpdate {

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 91645cc680022..99ac26cb43cac 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -4438,7 +4438,7 @@ void ASTWriter::GenerateSpecializationInfoLookupTable(
       Generator;
   LazySpecializationInfoLookupTrait Trait(*this);
 
-  llvm::DenseMap<unsigned, llvm::SmallVector<const NamedDecl *, 4>>
+  llvm::MapVector<unsigned, llvm::SmallVector<const NamedDecl *, 4>>
       SpecializationMaps;
 
   for (auto *Specialization : Specializations) {


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to