-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
…ting This patch gets call site splitting to use iterators for insertion rather than instruction pointers. When we switch on non-instr debug-info this becomes significant, as the iterators are going to signal whether or not a position is before or after debug-info. NFC as this isn't going to affect the output of any existing test.
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-debuginfo Author: Jeremy Morse (jmorse) ChangesThis patch gets call site splitting to use iterators for insertion rather than instruction pointers. When we switch on non-instr debug-info this becomes significant, as the iterators are going to signal whether or not a position is before or after debug-info. NFC as this isn't going to affect the output of any existing test. Full diff: https://github.com/llvm/llvm-project/pull/74455.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp b/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
index 47af299dbd473..015a0ab35987c 100644
--- a/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
+++ b/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
@@ -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);
}
@@ -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)
break;
}
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…te-splitting (#74455)" This reverts commit 34cdc91. Two buildbots say this is bad: https://lab.llvm.org/buildbot/#/builders/265/builds/861 https://lab.llvm.org/buildbot/#/builders/168/builds/17272
Reverted as some buildbots complained; closer inspection of the final part of the diff reveals the problem: `` |
if (CurrentI == OriginalBegin) | ||
if (CurrentI == &*OriginalBegin) |
There was a problem hiding this comment.
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.
(added inline comment rather than deal with github further); an obvious fix is to perform this check before the call to eraseFromParent. I'll hold off on this as I've got too much in-flight right now. |
Original commit message below; asan complained about this commit because it transpires that the final comparison with CurrentI is in fact a comparison of a pointer that has been freed. This seems to work fine most of the time, but using the iterator for such an instruction causes the freed instruction memory to be accessed, causing a use-after-free. The fix is to perform the comparison as an instruction, not an iterator. [NFC][DebugInfo][RemoveDIs] Use iterators to insert in callsite-splitting (#74455) This patch gets call site splitting to use iterators for insertion rather than instruction pointers. When we switch on non-instr debug-info this becomes significant, as the iterators are going to signal whether or not a position is before or after debug-info. NFC as this isn't going to affect the output of any existing test.
This patch gets call site splitting to use iterators for insertion rather than instruction pointers. When we switch on non-instr debug-info this becomes significant, as the iterators are going to signal whether or not a position is before or after debug-info.
NFC as this isn't going to affect the output of any existing test.