[llvm] DAG: Fix asserting on invalid inline asm constraints (PR #95935)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 18 07:38:20 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/95935.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+6-3)
- (added) llvm/test/CodeGen/AMDGPU/invalid-inline-asm-constraint-crash.ll (+52)
``````````diff
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/95935
More information about the llvm-commits
mailing list