[llvm] DAG: Fix asserting on invalid inline asm constraints (PR #95935)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 18 07:37:48 PDT 2024
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/95935
None
>From 6c1d8e1bf48628faca6820cfa80b4a2a62f6243c Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 2 Jul 2019 12:30:37 -0400
Subject: [PATCH] DAG: Fix asserting on invalid inline asm constraints
---
.../SelectionDAG/SelectionDAGBuilder.cpp | 9 ++--
.../invalid-inline-asm-constraint-crash.ll | 52 +++++++++++++++++++
2 files changed, 58 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/CodeGen/AMDGPU/invalid-inline-asm-constraint-crash.ll
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