Skip to content

Commit fa1de88

Browse files
committed
[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
1 parent 7cddf56 commit fa1de88

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

llvm/lib/IR/Metadata.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,21 @@ bool MetadataTracking::isReplaceable(const Metadata &MD) {
196196
}
197197

198198
SmallVector<Metadata *, 4> ReplaceableMetadataImpl::getAllArgListUsers() {
199-
SmallVector<Metadata *, 4> MDUsers;
199+
SmallVector<std::pair<OwnerTy, uint64_t> *> MDUsersWithID;
200200
for (auto Pair : UseMap) {
201201
OwnerTy Owner = Pair.second.first;
202202
if (!Owner.is<Metadata *>())
203203
continue;
204204
Metadata *OwnerMD = Owner.get<Metadata *>();
205205
if (OwnerMD->getMetadataID() == Metadata::DIArgListKind)
206-
MDUsers.push_back(OwnerMD);
206+
MDUsersWithID.push_back(&UseMap[Pair.first]);
207207
}
208+
llvm::sort(MDUsersWithID, [](auto UserA, auto UserB) {
209+
return UserA->second < UserB->second;
210+
});
211+
SmallVector<Metadata *> MDUsers;
212+
for (auto UserWithID : MDUsersWithID)
213+
MDUsers.push_back(UserWithID->first.get<Metadata *>());
208214
return MDUsers;
209215
}
210216

0 commit comments

Comments
 (0)