[llvm] [AMDGPU] Fix assert on empty inline asm register constraint (PR #225743)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 05:07:54 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Arseniy Obolenskiy (aobolensk)

<details>
<summary>Changes</summary>

An empty register name reaches this parser from user source, where StringRef::front() asserts

---
Full diff: https://github.com/llvm/llvm-project/pull/225743.diff


2 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp (+3) 
- (modified) llvm/test/CodeGen/AMDGPU/inline-asm-out-of-bounds-register.ll (+12) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index 0a5304bb0fd71..e45359719d6c9 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -1530,6 +1530,9 @@ static bool isValidRegPrefix(char C) {
 }
 
 std::tuple<char, unsigned, unsigned> parseAsmPhysRegName(StringRef RegName) {
+  if (RegName.empty())
+    return {};
+
   char Kind = RegName.front();
   if (!isValidRegPrefix(Kind))
     return {};
diff --git a/llvm/test/CodeGen/AMDGPU/inline-asm-out-of-bounds-register.ll b/llvm/test/CodeGen/AMDGPU/inline-asm-out-of-bounds-register.ll
index 5bb33a0b8be9d..e53e925cd18cc 100644
--- a/llvm/test/CodeGen/AMDGPU/inline-asm-out-of-bounds-register.ll
+++ b/llvm/test/CodeGen/AMDGPU/inline-asm-out-of-bounds-register.ll
@@ -97,3 +97,15 @@ define void @overflow_bitwidth_1() {
   ret void
 }
 
+; CHECK: error: could not allocate input reg for constraint '{}'
+define void @empty_reg_name() {
+  tail call void asm sideeffect "; use %0", "{}"(i64 123)
+  ret void
+}
+
+; CHECK: error: could not allocate output register for constraint '{}'
+define void @empty_reg_name_def() {
+  %v = tail call i32 asm sideeffect "v_mov_b32 $0, -1", "={}"()
+  ret void
+}
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/225743


More information about the llvm-commits mailing list