Skip to content

Commit 35a364f

Browse files
[TargetLowering] fix index OOB (#67494)
I accidentally introduced this in commit 330fa7d ("[TargetLowering] Deduplicate choosing InlineAsm constraint between ISels (#67057)") Fix forward.
1 parent eb0a9a1 commit 35a364f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5889,9 +5889,15 @@ void TargetLowering::ComputeConstraintToUse(AsmOperandInfo &OpInfo,
58895889
for (const unsigned E = G.size();
58905890
BestIdx < E && (G[BestIdx].second == TargetLowering::C_Other ||
58915891
G[BestIdx].second == TargetLowering::C_Immediate);
5892-
++BestIdx)
5892+
++BestIdx) {
58935893
if (lowerImmediateIfPossible(G[BestIdx], Op, DAG, *this))
58945894
break;
5895+
// If we're out of constraints, just pick the first one.
5896+
if (BestIdx + 1 == E) {
5897+
BestIdx = 0;
5898+
break;
5899+
}
5900+
}
58955901

58965902
OpInfo.ConstraintCode = G[BestIdx].first;
58975903
OpInfo.ConstraintType = G[BestIdx].second;

llvm/test/CodeGen/X86/inline-asm-bad-constraint-n.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ define void @foo() {
88
call void asm sideeffect "foo $0", "n"(ptr %a) nounwind
99
ret void
1010
}
11+
12+
; CHECK: error: invalid operand for inline asm constraint 'i'
13+
define void @bar(i32 %v) {
14+
call void asm "", "in"(i32 %v)
15+
ret void
16+
}

llvm/test/CodeGen/X86/inline-asm-n-constraint.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ define void @foo() {
77
call void asm sideeffect "foo $0", "n"(i32 42) nounwind
88
; CHECK: #APP
99
; CHECK-NEXT: foo $42
10+
; CHECK-NEXT: #NO_APP
11+
call void asm "# $0", "in"(i32 1392848979)
12+
; CHECK-NEXT: #APP
13+
; CHECK-NEXT: # $1392848979
1014
; CHECK-NEXT: #NO_APP
1115
ret void
1216
; CHECK-NEXT: retq

0 commit comments

Comments
 (0)