Skip to content

[NFC][DebugInfo][RemoveDIs] Use iterators to insert in callsite-splitting #74455

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
Dec 5, 2023
Merged
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
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ static void splitCallSite(CallBase &CB,
return;
}

auto *OriginalBegin = &*TailBB->begin();
BasicBlock::iterator OriginalBegin = TailBB->begin();
// Replace users of the original call with a PHI mering call-sites split.
if (CallPN) {
CallPN->insertBefore(OriginalBegin);
CallPN->insertBefore(*TailBB, OriginalBegin);
CB.replaceAllUsesWith(CallPN);
}

Expand All @@ -399,13 +399,13 @@ static void splitCallSite(CallBase &CB,
for (auto &Mapping : ValueToValueMaps)
NewPN->addIncoming(Mapping[CurrentI],
cast<Instruction>(Mapping[CurrentI])->getParent());
NewPN->insertBefore(&*TailBB->begin());
NewPN->insertBefore(*TailBB, TailBB->begin());
CurrentI->replaceAllUsesWith(NewPN);
}
CurrentI->dropDbgValues();
CurrentI->eraseFromParent();
// We are done once we handled the first original instruction in TailBB.
if (CurrentI == OriginalBegin)
if (CurrentI == &*OriginalBegin)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After being bitten by the buildbots: it turns out in the old version this was a comparison between a freed pointer and another pointer. Turning one of them into an iterator involves dereferencing it, it checking whether it's a sentinel, and subsequently asan firing because of a use-after-free.

break;
}
}
Expand Down