[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
This commit is contained in:
Stephen Tozer 2021-06-17 13:58:34 +01:00
parent 7cddf56d60
commit fa1de88f81
1 changed files with 8 additions and 2 deletions

View File

@ -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;
}