Skip to content

[DIArgList] Re-unique after changing operands to fix non-determinism #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/IR/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ struct TempMDNodeDeleter {
class MDNode : public Metadata {
friend class ReplaceableMetadataImpl;
friend class LLVMContextImpl;
friend class DIArgList;

unsigned NumOperands;
unsigned NumUnresolved;
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/IR/DebugInfoMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,12 @@ void DIArgList::handleChangedOperand(void *Ref, Metadata *New) {
assert((!New || isa<ValueAsMetadata>(New)) &&
"DIArgList must be passed a ValueAsMetadata");
untrack();
bool Uniq = isUniqued();
if (Uniq) {
// We need to update the uniqueness once the Args are updated since they
// form the key to the DIArgLists store.
eraseFromStore();
}
ValueAsMetadata *NewVM = cast_or_null<ValueAsMetadata>(New);
for (ValueAsMetadata *&VM : Args) {
if (&VM == OldVMPtr) {
Expand All @@ -1601,6 +1607,10 @@ void DIArgList::handleChangedOperand(void *Ref, Metadata *New) {
VM = ValueAsMetadata::get(UndefValue::get(VM->getValue()->getType()));
}
}
if (Uniq) {
if (uniquify() != this)
storeDistinctInContext();
}
track();
}
void DIArgList::track() {
Expand Down
9 changes: 8 additions & 1 deletion llvm/lib/IR/LLVMContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ LLVMContextImpl::~LLVMContextImpl() {

// Drop references for MDNodes. Do this before Values get deleted to avoid
// unnecessary RAUW when nodes are still unresolved.
for (auto *I : DistinctMDNodes)
for (auto *I : DistinctMDNodes) {
// We may have DIArgList that were uniqued, and as it has a custom
// implementation of dropAllReferences, it needs to be explicitly invoked.
if (auto *AL = dyn_cast<DIArgList>(I)) {
AL->dropAllReferences();
continue;
}
I->dropAllReferences();
}
#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
for (auto *I : CLASS##s) \
I->dropAllReferences();
Expand Down