[llvm] 35a364f - [TargetLowering] fix index OOB (#67494)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 15:50:30 PDT 2023


Author: Nick Desaulniers
Date: 2023-09-26T15:50:26-07:00
New Revision: 35a364fa5ca00aaac78bc1da8b34a5c19796f01c

URL: https://github.com/llvm/llvm-project/commit/35a364fa5ca00aaac78bc1da8b34a5c19796f01c
DIFF: https://github.com/llvm/llvm-project/commit/35a364fa5ca00aaac78bc1da8b34a5c19796f01c.diff

LOG: [TargetLowering] fix index OOB (#67494)

I accidentally introduced this in

commit 330fa7d2a4e0 ("[TargetLowering] Deduplicate choosing InlineAsm
constraint between ISels (#67057)")

Fix forward.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
    llvm/test/CodeGen/X86/inline-asm-bad-constraint-n.ll
    llvm/test/CodeGen/X86/inline-asm-n-constraint.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 3b259d99f0029ca..55aece7edc9ca69 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -5889,9 +5889,15 @@ void TargetLowering::ComputeConstraintToUse(AsmOperandInfo &OpInfo,
     for (const unsigned E = G.size();
          BestIdx < E && (G[BestIdx].second == TargetLowering::C_Other ||
                          G[BestIdx].second == TargetLowering::C_Immediate);
-         ++BestIdx)
+         ++BestIdx) {
       if (lowerImmediateIfPossible(G[BestIdx], Op, DAG, *this))
         break;
+      // If we're out of constraints, just pick the first one.
+      if (BestIdx + 1 == E) {
+        BestIdx = 0;
+        break;
+      }
+    }
 
     OpInfo.ConstraintCode = G[BestIdx].first;
     OpInfo.ConstraintType = G[BestIdx].second;

diff  --git a/llvm/test/CodeGen/X86/inline-asm-bad-constraint-n.ll b/llvm/test/CodeGen/X86/inline-asm-bad-constraint-n.ll
index 41d8a9baa8dd4e1..d27a74620013bbd 100644
--- a/llvm/test/CodeGen/X86/inline-asm-bad-constraint-n.ll
+++ b/llvm/test/CodeGen/X86/inline-asm-bad-constraint-n.ll
@@ -8,3 +8,9 @@ define void @foo() {
   call void asm sideeffect "foo $0", "n"(ptr %a) nounwind
   ret void
 }
+
+; CHECK: error: invalid operand for inline asm constraint 'i'
+define void @bar(i32 %v) {
+  call void asm "", "in"(i32 %v)
+  ret void
+}

diff  --git a/llvm/test/CodeGen/X86/inline-asm-n-constraint.ll b/llvm/test/CodeGen/X86/inline-asm-n-constraint.ll
index 669e464f1f6f89f..4774d43ee333f0b 100644
--- a/llvm/test/CodeGen/X86/inline-asm-n-constraint.ll
+++ b/llvm/test/CodeGen/X86/inline-asm-n-constraint.ll
@@ -7,6 +7,10 @@ define void @foo() {
   call void asm sideeffect "foo $0", "n"(i32 42) nounwind
 ; CHECK:      #APP
 ; CHECK-NEXT: foo    $42
+; CHECK-NEXT: #NO_APP
+  call void asm "# $0", "in"(i32 1392848979)
+; CHECK-NEXT: #APP
+; CHECK-NEXT: # $1392848979
 ; CHECK-NEXT: #NO_APP
   ret void
 ; CHECK-NEXT: retq


        


More information about the llvm-commits mailing list