-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[MachineBasicBlock] Fix use after free in SplitCriticalEdge #66188
Conversation
Remove use after free when attempting to update SlotIndexes in MachineBasicBlock::SplitCriticalEdge. Add support to targets for updating SlotIndexes when inserting or removing branches.
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-backend-msp430 ChangesRemove use after free when attempting to update SlotIndexes in MachineBasicBlock::SplitCriticalEdge. Add support to targets for updating SlotIndexes when inserting or removing branches. --Patch is 127.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/66188.diff 51 Files Affected:
<pre>
diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -702,17 +704,18 @@ class TargetInstrInfo : public MCInstrInfo {
void MachineBasicBlock::updateTerminator(
@@ -693,7 +693,7 @@ void MachineBasicBlock::updateTerminator(
@@ -1166,51 +1170,20 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge( ReplaceUsesOfBlockWith(Succ, NMBB);
// Insert unconditional "jump Succ" instruction in NMBB if necessary.
// Fix PHI nodes in Succ so they refer to NMBB instead of this. -#include "AArch64ExpandImm.h" unsigned AArch64InstrInfo::removeBranch(MachineBasicBlock &MBB,
I = MBB.end(); // Remove the branch.
-void AArch64InstrInfo::instantiateCondBranch(
-unsigned AArch64InstrInfo::insertBranch(
if (BytesAdded)
using namespace llvm; @@ -730,14 +731,16 @@ unsigned R600InstrInfo::insertBranch(MachineBasicBlock &MBB, |
This touches all backends, but the code changes are very fairly straightforward and similar between most. |
@@ -693,15 +693,15 @@ void MachineBasicBlock::updateTerminator( | |||
MachineBasicBlock *TBB = nullptr, *FBB = nullptr; | |||
SmallVector<MachineOperand, 4> Cond; | |||
DebugLoc DL = findBranchDebugLoc(); | |||
bool B = TII->analyzeBranch(*this, TBB, FBB, Cond); | |||
bool B = TII->analyzeBranch(*this, TBB, FBB, Cond, /*AllowModify=*/false); |
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.
This change is NFC, right?
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.
This is NFC, but I felt it was appropriate to add an explicit configuration of AllowModify=false here as SlotIndexes will be invalidated if analyzeBranch modifies the instructions.
LGTM overall. I would suggest that approval from a small handful of target maintainers is enough to merge this. |
Could we fix |
I am open to alternatives. |
- Reverse order of Indexes and BytesAdded/BytesRemoved - Describe new parameters in comments
The listener alternative sounds better to me. |
Close this in favour of observer pattern in #68786. |
Remove use after free when attempting to update SlotIndexes in MachineBasicBlock::SplitCriticalEdge.
Add support to targets for updating SlotIndexes when inserting or removing branches.