[llvm] [AMDGPU] Fix assert on empty inline asm register constraint (PR #225743)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 07:12:00 PDT 2026
https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/225743
>From dc1b3b5c10466fae141548df3d1bfb65842ecb77 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Wed, 23 Sep 2026 14:06:02 +0200
Subject: [PATCH] [AMDGPU] Fix assert on empty inline asm register constraint
An empty register name reaches this parser from user source, where StringRef::front() asserts
---
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp | 3 +++
.../AMDGPU/inline-asm-out-of-bounds-register.ll | 12 ++++++++++++
2 files changed, 15 insertions(+)
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index 0a5304bb0fd713..e45359719d6c97 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 5bb33a0b8be9d0..e53e925cd18cce 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
+}
+
More information about the llvm-commits
mailing list