[llvm] [SPIRV] Error in backend for vararg functions (PR #169111)
Nick Sarnie via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 24 08:14:03 PST 2025
https://github.com/sarnex updated https://github.com/llvm/llvm-project/pull/169111
>From cad5f4a3bb0566cf03919326f830e56f0443a30e Mon Sep 17 00:00:00 2001
From: Nick Sarnie <nick.sarnie at intel.com>
Date: Fri, 21 Nov 2025 14:19:38 -0800
Subject: [PATCH 1/3] [SPIRV] Error in backend for vararg functions
Signed-off-by: Nick Sarnie <nick.sarnie at intel.com>
---
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 10 +++++++---
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h | 2 +-
llvm/test/CodeGen/SPIRV/function/vararg.ll | 17 +++++++++++++++++
3 files changed, 25 insertions(+), 4 deletions(-)
create mode 100644 llvm/test/CodeGen/SPIRV/function/vararg.ll
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 76fd834fd7219..b3f0478ecb8bf 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -970,8 +970,11 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeForwardPointer(
}
SPIRVType *SPIRVGlobalRegistry::getOpTypeFunction(
- SPIRVType *RetType, const SmallVectorImpl<SPIRVType *> &ArgTypes,
+ const FunctionType *Ty, SPIRVType *RetType,
+ const SmallVectorImpl<SPIRVType *> &ArgTypes,
MachineIRBuilder &MIRBuilder) {
+ if (Ty->isVarArg())
+ reportFatalUsageError("SPIR-V does not support variadic functions");
return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
auto MIB = MIRBuilder.buildInstr(SPIRV::OpTypeFunction)
.addDef(createTypeVReg(MIRBuilder))
@@ -988,7 +991,8 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateOpTypeFunctionWithArgs(
MachineIRBuilder &MIRBuilder) {
if (const MachineInstr *MI = findMI(Ty, false, &MIRBuilder.getMF()))
return MI;
- const MachineInstr *NewMI = getOpTypeFunction(RetType, ArgTypes, MIRBuilder);
+ const MachineInstr *NewMI =
+ getOpTypeFunction(cast<FunctionType>(Ty), RetType, ArgTypes, MIRBuilder);
add(Ty, false, NewMI);
return finishCreatingSPIRVType(Ty, NewMI);
}
@@ -1097,7 +1101,7 @@ SPIRVType *SPIRVGlobalRegistry::createSPIRVType(
for (const auto &ParamTy : FType->params())
ParamTypes.push_back(findSPIRVType(ParamTy, MIRBuilder, AccQual,
ExplicitLayoutRequired, EmitIR));
- return getOpTypeFunction(RetTy, ParamTypes, MIRBuilder);
+ return getOpTypeFunction(FType, RetTy, ParamTypes, MIRBuilder);
}
unsigned AddrSpace = typeToAddressSpace(Ty);
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
index c230e62e795e8..09c77f0cfd4f5 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
@@ -464,7 +464,7 @@ class SPIRVGlobalRegistry : public SPIRVIRMapping {
SPIRVType *getOpTypeForwardPointer(SPIRV::StorageClass::StorageClass SC,
MachineIRBuilder &MIRBuilder);
- SPIRVType *getOpTypeFunction(SPIRVType *RetType,
+ SPIRVType *getOpTypeFunction(const FunctionType *Ty, SPIRVType *RetType,
const SmallVectorImpl<SPIRVType *> &ArgTypes,
MachineIRBuilder &MIRBuilder);
diff --git a/llvm/test/CodeGen/SPIRV/function/vararg.ll b/llvm/test/CodeGen/SPIRV/function/vararg.ll
new file mode 100644
index 0000000000000..02a172356b62b
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/function/vararg.ll
@@ -0,0 +1,17 @@
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - 2>&1 | FileCheck %s
+
+ at glob = addrspace(1) global ptr null, align 8
+
+; Function Attrs: mustprogress noinline norecurse optnone
+define noundef i32 @main() {
+entry:
+ %retval = alloca i32, align 4
+ %retval.ascast = addrspacecast ptr %retval to ptr addrspace(4)
+ store i32 0, ptr addrspace(4) %retval.ascast, align 4
+ store ptr @_Z3fooiz, ptr addrspace(4) addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)), align 8
+ call spir_func void (i32, ...) @_Z3fooiz(i32 noundef 5, i32 noundef 3)
+ ret i32 0
+}
+
+; CHECK: SPIR-V does not support variadic functions
+declare spir_func void @_Z3fooiz(i32 noundef, ...)
>From 9efe2f40a7e1f1da4b662a72d2c366300c65b621 Mon Sep 17 00:00:00 2001
From: Nick Sarnie <nick.sarnie at intel.com>
Date: Mon, 24 Nov 2025 07:39:52 -0800
Subject: [PATCH 2/3] simplify test and improve error
Signed-off-by: Nick Sarnie <nick.sarnie at intel.com>
---
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 9 +++++++--
llvm/test/CodeGen/SPIRV/function/vararg.ll | 16 +++++-----------
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index b3f0478ecb8bf..bd0c7d15afd12 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -21,6 +21,7 @@
#include "SPIRVUtils.h"
#include "llvm/ADT/APInt.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicsSPIRV.h"
@@ -973,8 +974,12 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeFunction(
const FunctionType *Ty, SPIRVType *RetType,
const SmallVectorImpl<SPIRVType *> &ArgTypes,
MachineIRBuilder &MIRBuilder) {
- if (Ty->isVarArg())
- reportFatalUsageError("SPIR-V does not support variadic functions");
+ if (Ty->isVarArg()) {
+ Function &Fn = MIRBuilder.getMF().getFunction();
+ Ty->getContext().diagnose(DiagnosticInfoUnsupported(
+ Fn, "SPIR-V does not support variadic functions",
+ MIRBuilder.getDebugLoc()));
+ }
return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
auto MIB = MIRBuilder.buildInstr(SPIRV::OpTypeFunction)
.addDef(createTypeVReg(MIRBuilder))
diff --git a/llvm/test/CodeGen/SPIRV/function/vararg.ll b/llvm/test/CodeGen/SPIRV/function/vararg.ll
index 02a172356b62b..c6c68ff0c43e1 100644
--- a/llvm/test/CodeGen/SPIRV/function/vararg.ll
+++ b/llvm/test/CodeGen/SPIRV/function/vararg.ll
@@ -1,17 +1,11 @@
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - 2>&1 | FileCheck %s
- at glob = addrspace(1) global ptr null, align 8
-
; Function Attrs: mustprogress noinline norecurse optnone
-define noundef i32 @main() {
+define void @bar() {
entry:
- %retval = alloca i32, align 4
- %retval.ascast = addrspacecast ptr %retval to ptr addrspace(4)
- store i32 0, ptr addrspace(4) %retval.ascast, align 4
- store ptr @_Z3fooiz, ptr addrspace(4) addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)), align 8
- call spir_func void (i32, ...) @_Z3fooiz(i32 noundef 5, i32 noundef 3)
- ret i32 0
+ call spir_func void (i32, ...) @_Z3fooiz(i32 5, i32 3)
+ ret void
}
-; CHECK: SPIR-V does not support variadic functions
-declare spir_func void @_Z3fooiz(i32 noundef, ...)
+; CHECK:error: {{.*}} in function bar void (): SPIR-V does not support variadic functions
+declare spir_func void @_Z3fooiz(i32, ...)
>From d2319d8705bd79c7417ae3c8ae54b5337c43763a Mon Sep 17 00:00:00 2001
From: Nick Sarnie <nick.sarnie at intel.com>
Date: Mon, 24 Nov 2025 08:13:35 -0800
Subject: [PATCH 3/3] address test feedback
Signed-off-by: Nick Sarnie <nick.sarnie at intel.com>
---
llvm/test/CodeGen/SPIRV/function/vararg.ll | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/test/CodeGen/SPIRV/function/vararg.ll b/llvm/test/CodeGen/SPIRV/function/vararg.ll
index c6c68ff0c43e1..7f734834ccf51 100644
--- a/llvm/test/CodeGen/SPIRV/function/vararg.ll
+++ b/llvm/test/CodeGen/SPIRV/function/vararg.ll
@@ -1,6 +1,5 @@
-; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - 2>&1 | FileCheck %s
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers < %s 2>&1 | FileCheck %s
-; Function Attrs: mustprogress noinline norecurse optnone
define void @bar() {
entry:
call spir_func void (i32, ...) @_Z3fooiz(i32 5, i32 3)
More information about the llvm-commits
mailing list