[llvm] [SPIR-V] Fix crash on get_global_id with non-integer dimension index (PR #208152)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 7 23:53:27 PDT 2026
https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/208152
None
>From 9813254c71167c0670817c1c85d7fe2e12519236 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Wed, 8 Jul 2026 08:38:38 +0200
Subject: [PATCH] [SPIR-V] Fix crash on get_global_id with non-integer
dimension index
---
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 3 +++
.../SPIRV/get-global-id-non-integer-dim.ll | 15 +++++++++++++++
2 files changed, 18 insertions(+)
create mode 100644 llvm/test/CodeGen/SPIRV/get-global-id-non-integer-dim.ll
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index 7f01fc37af545..dc3088a3901e0 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -1685,6 +1685,9 @@ static bool genWorkgroupQuery(const SPIRV::IncomingCall *Call,
SPIRV::BuiltIn::BuiltIn BuiltinValue,
uint64_t DefaultValue) {
Register IndexRegister = Call->Arguments[0];
+ SPIRVTypeInst IndexRegisterType = GR->getSPIRVTypeForVReg(IndexRegister);
+ if (!IndexRegisterType || IndexRegisterType->getOpcode() != SPIRV::OpTypeInt)
+ report_fatal_error("Expect an integer <Dimindx> argument");
const unsigned ResultWidth = Call->ReturnType->getOperand(1).getImm();
const unsigned PointerSize = GR->getPointerSize();
const SPIRVTypeInst PointerSizeType =
diff --git a/llvm/test/CodeGen/SPIRV/get-global-id-non-integer-dim.ll b/llvm/test/CodeGen/SPIRV/get-global-id-non-integer-dim.ll
new file mode 100644
index 0000000000000..59e62493fe890
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/get-global-id-non-integer-dim.ll
@@ -0,0 +1,15 @@
+; RUN: not --crash llc -O0 -mtriple=spirv64-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not --crash llc -O2 -mtriple=spirv64-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
+
+; get_global_id and its sibling workgroup-query builtins take an integer
+; dimension index.
+
+; CHECK: LLVM ERROR: Expect an integer <Dimindx> argument
+
+declare spir_func i64 @_Z13get_global_idj(bfloat)
+
+define spir_kernel void @fuzz_kernel(ptr addrspace(1) %out, bfloat %dim) {
+ %id = call spir_func i64 @_Z13get_global_idj(bfloat %dim)
+ store i64 %id, ptr addrspace(1) %out
+ ret void
+}
More information about the llvm-commits
mailing list