From: Stephen Tozer Date: Thu, 17 Jun 2021 12:58:34 +0000 (+0100) Subject: [DebugInfo] Prevent non-determinism when updating DIArgList users of a value X-Git-Tag: llvmorg-14-init~3708 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fa1de88f81e9c6db5255ca7c4d0fd25606c5a054;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 4d6ccfa..f039d91f 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -196,15 +196,21 @@ bool MetadataTracking::isReplaceable(const Metadata &MD) { } SmallVector ReplaceableMetadataImpl::getAllArgListUsers() { - SmallVector MDUsers; + SmallVector *> MDUsersWithID; for (auto Pair : UseMap) { OwnerTy Owner = Pair.second.first; if (!Owner.is()) continue; Metadata *OwnerMD = Owner.get(); 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 MDUsers; + for (auto UserWithID : MDUsersWithID) + MDUsers.push_back(UserWithID->first.get()); return MDUsers; }