Skip to content

Commit 1e51296

Browse files
shiltiangithub-actions[bot]
authored andcommitted
Automerge: [RegAlloc] Fix use-after-free in RegAllocBase::cleanupFailedVReg (#151435)
#128400 introduced a use-after-free bug in `RegAllocBase::cleanupFailedVReg` when removing intervals from regunits. The issue is from the `InterferenceCache` in `RAGreedy`, which holds `LiveRange*`. The current `InterferenceCache` APIs make it difficult to update it, and there isn't a straightforward way to do that. Since #128400 already mentions it's not clear about the necessity of removing intervals from regunits, this PR avoids the issue by simply skipping that step. Fixes SWDEV-527146.
2 parents 042e83f + faa4c4c commit 1e51296

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

llvm/lib/CodeGen/RegAllocBase.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,8 @@ void RegAllocBase::cleanupFailedVReg(Register FailedReg, MCRegister PhysReg,
178178
for (MCRegAliasIterator Aliases(PhysReg, TRI, true); Aliases.isValid();
179179
++Aliases) {
180180
for (MachineOperand &MO : MRI->reg_operands(*Aliases)) {
181-
if (MO.readsReg()) {
181+
if (MO.readsReg())
182182
MO.setIsUndef(true);
183-
LIS->removeAllRegUnitsForPhysReg(MO.getReg());
184-
}
185183
}
186184
}
187185
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: not llc -mcpu=gfx1100 -mtriple=amdgcn-amd-amdhsa -stress-regalloc=4 -filetype=null -verify-machineinstrs %s 2>&1 | FileCheck %s
2+
3+
; CHECK: error: <unknown>:0:0: ran out of registers during register allocation in function 'f'
4+
; CHECK-NOT: Bad machine code
5+
6+
define <16 x half> @f(i1 %LGV2, <16 x half> %0) {
7+
BB:
8+
br i1 %LGV2, label %SW_C3, label %SW_C
9+
10+
SW_C: ; preds = %BB
11+
%B1 = fmul <16 x half> %0, zeroinitializer
12+
ret <16 x half> %B1
13+
14+
SW_C3: ; preds = %BB
15+
ret <16 x half> <half 0xH0000, half poison, half poison, half poison, half poison, half poison, half poison, half poison, half poison, half poison, half poison, half poison, half poison, half poison, half poison, half poison>
16+
}

0 commit comments

Comments
 (0)