diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2024-06-18 18:51:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 18:51:29 +0200 |
commit | 62b5196be0f8ab9b3e73ccfd6a4ee0f1598d6f1c (patch) | |
tree | 31f2082a918cfa875bbb1ea0253e5d1b417bb745 | |
parent | b629d4b91291328090023b5405dbbaabfd38d961 (diff) | |
download | llvm-62b5196be0f8ab9b3e73ccfd6a4ee0f1598d6f1c.zip llvm-62b5196be0f8ab9b3e73ccfd6a4ee0f1598d6f1c.tar.gz llvm-62b5196be0f8ab9b3e73ccfd6a4ee0f1598d6f1c.tar.bz2 |
DAG: Fix asserting on invalid inline asm constraints (#95935)
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 9 | ||||
-rw-r--r-- | llvm/test/CodeGen/AMDGPU/invalid-inline-asm-constraint-crash.ll | 52 |
2 files changed, 58 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 453bc71..3f5d1a5 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 0000000..ec58686 --- /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 +} |