[llvm] 62b5196 - DAG: Fix asserting on invalid inline asm constraints (#95935)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 09:51:32 PDT 2024


Author: Matt Arsenault
Date: 2024-06-18T18:51:29+02:00
New Revision: 62b5196be0f8ab9b3e73ccfd6a4ee0f1598d6f1c

URL: https://github.com/llvm/llvm-project/commit/62b5196be0f8ab9b3e73ccfd6a4ee0f1598d6f1c
DIFF: https://github.com/llvm/llvm-project/commit/62b5196be0f8ab9b3e73ccfd6a4ee0f1598d6f1c.diff

LOG: DAG: Fix asserting on invalid inline asm constraints (#95935)

Added: 
    llvm/test/CodeGen/AMDGPU/invalid-inline-asm-constraint-crash.ll

Modified: 
    llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 453bc7129b5b0..3f5d1a5047a42 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -10023,9 +10023,12 @@ void SelectionDAGBuilder::visitInlineAsm(const CallBase &Call,
         break;
       }
 
-      assert((OpInfo.ConstraintType == TargetLowering::C_RegisterClass ||
-              OpInfo.ConstraintType == TargetLowering::C_Register) &&
-             "Unknown constraint type!");
+      if (OpInfo.ConstraintType != TargetLowering::C_RegisterClass &&
+          OpInfo.ConstraintType != TargetLowering::C_Register) {
+        emitInlineAsmError(Call, "unknown asm constraint '" +
+                                     Twine(OpInfo.ConstraintCode) + "'");
+        return;
+      }
 
       // TODO: Support this.
       if (OpInfo.isIndirect) {

diff  --git a/llvm/test/CodeGen/AMDGPU/invalid-inline-asm-constraint-crash.ll b/llvm/test/CodeGen/AMDGPU/invalid-inline-asm-constraint-crash.ll
new file mode 100644
index 0000000000000..ec58686630bf2
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/invalid-inline-asm-constraint-crash.ll
@@ -0,0 +1,52 @@
+; RUN: not llc -march=amdgcn < %s 2>&1 | FileCheck -check-prefix=ERR %s
+
+; ERR: error: couldn't allocate output register for constraint 'q'
+define void @crash_use_invalid_output_constraint_block(ptr addrspace(1) %arg) {
+bb:
+  %v = call i32 asm sideeffect "", "=q"()
+  br label %use
+
+use:
+  store i32 %v, ptr addrspace(1) %arg
+  ret void
+}
+
+; ERR: error: unknown asm constraint 'q'
+define void @invalid_input_constraint() {
+  call void asm sideeffect "", "q"(i32 1)
+  ret void
+}
+
+; ERR: error: unknown asm constraint 'q'
+define void @invalid_input_constraint_multi() {
+  call void asm sideeffect "", "q,q"(i32 1, i16 2)
+  ret void
+}
+
+; ERR: error: unknown asm constraint 'q'
+define void @invalid_input_constraint_multi_valid() {
+  call void asm sideeffect "", "q,v"(i32 1, i64 2)
+  ret void
+}
+
+; ERR: error: couldn't allocate output register for constraint 'q'
+define void @crash_use_invalid_output_constraint_block_multi(ptr addrspace(1) %arg) {
+bb:
+  %v = call { i32, i32 } asm sideeffect "", "=q,=q"()
+  br label %use
+
+use:
+  store { i32, i32 } %v, ptr addrspace(1) %arg
+  ret void
+}
+
+; ERR: error: couldn't allocate output register for constraint 'q'
+define void @crash_use_invalid_output_constraint_block_multi_valid(ptr addrspace(1) %arg) {
+bb:
+  %v = call { i32, i32 } asm sideeffect "", "=q,=v"()
+  br label %use
+
+use:
+  store { i32, i32 } %v, ptr addrspace(1) %arg
+  ret void
+}


        


More information about the llvm-commits mailing list