[llvm] fa1de88 - [DebugInfo] Prevent non-determinism when updating DIArgList users of a value

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 17 07:09:41 PDT 2021


Author: Stephen Tozer
Date: 2021-06-17T15:09:27+01:00
New Revision: fa1de88f81e9c6db5255ca7c4d0fd25606c5a054

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

LOG: [DebugInfo] Prevent non-determinism when updating DIArgList users of a value

This patch fixes an issue where builds of programs with multiple dbg.values
with DIArgList locations could have non-deterministic output. This issue
was caused by ReplaceableMetadataImpl::getAllArgListUsers, which
returned DIArgList pointers in a random order; the output of this
function would later be used to insert dbg.values, causing the order of
insertion to be non-deterministic. This patch changes getAllArgListUsers
to return pointers in a fixed order.

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

Added: 
    

Modified: 
    llvm/lib/IR/Metadata.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 4d6ccfa43a640..f039d91f82a4a 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -196,15 +196,21 @@ bool MetadataTracking::isReplaceable(const Metadata &MD) {
 }
 
 SmallVector<Metadata *, 4> ReplaceableMetadataImpl::getAllArgListUsers() {
-  SmallVector<Metadata *, 4> MDUsers;
+  SmallVector<std::pair<OwnerTy, uint64_t> *> MDUsersWithID;
   for (auto Pair : UseMap) {
     OwnerTy Owner = Pair.second.first;
     if (!Owner.is<Metadata *>())
       continue;
     Metadata *OwnerMD = Owner.get<Metadata *>();
     if (OwnerMD->getMetadataID() == Metadata::DIArgListKind)
-      MDUsers.push_back(OwnerMD);
+      MDUsersWithID.push_back(&UseMap[Pair.first]);
   }
+  llvm::sort(MDUsersWithID, [](auto UserA, auto UserB) {
+    return UserA->second < UserB->second;
+  });
+  SmallVector<Metadata *> MDUsers;
+  for (auto UserWithID : MDUsersWithID)
+    MDUsers.push_back(UserWithID->first.get<Metadata *>());
   return MDUsers;
 }
 


        


More information about the llvm-commits mailing list