Skip to content

Commit 042ffe9

Browse files
committed
Avoid bitwidth overflow issue
1 parent b917c11 commit 042ffe9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16712,13 +16712,14 @@ SITargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI_,
1671216712

1671316713
if (RC) {
1671416714
if (NumRegs > 1) {
16715+
if (Idx >= RC->getNumRegs() || Idx + NumRegs - 1 > RC->getNumRegs())
16716+
return std::pair(0U, nullptr);
16717+
1671516718
uint32_t Width = NumRegs * 32;
1671616719
// Prohibit constraints for register ranges with a width that does not
1671716720
// match the required type.
1671816721
if (VT.SimpleTy != MVT::Other && Width != VT.getSizeInBits())
1671916722
return std::pair(0U, nullptr);
16720-
if (Idx >= RC->getNumRegs())
16721-
return std::pair(0U, nullptr);
1672216723

1672316724
MCRegister Reg = RC->getRegister(Idx);
1672416725
if (SIRegisterInfo::isVGPRClass(RC))

llvm/test/CodeGen/AMDGPU/inline-asm-out-of-bounds-register.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,21 @@ define void @vgpr32_last_is_uintmax_p1() {
8383
tail call void asm sideeffect "; use %0", "{v[4294967265:4294967296]}"(i64 123)
8484
ret void
8585
}
86+
87+
; CHECK: error: couldn't allocate input reg for constraint '{v[2:2147483651]}'
88+
define void @overflow_bitwidth_0() {
89+
tail call void asm sideeffect "; use %0", "{v[2:2147483651]}"(i64 123)
90+
ret void
91+
}
92+
93+
; CHECK: error: couldn't allocate input reg for constraint '{v[2147483635:2147483651]}'
94+
define void @overflow_bitwidth_1() {
95+
tail call void asm sideeffect "; use %0", "{v[2147483635:2147483651]}"(i64 123)
96+
ret void
97+
}
98+
99+
; CHECK: error: couldn't allocate input reg for constraint '{v[2147483635:2147483651]}'
100+
define void @overflow_bitwidth_2() {
101+
tail call void asm sideeffect "; use %0", "{v[2147483635:2147483651]}"(i64 123)
102+
ret void
103+
}

0 commit comments

Comments
 (0)