Skip to content

Commit 569972a

Browse files
authored
Report error when finding variadic function other than printf (#2703)
Variadic functions are not supported in SPIR-V, the only known exception is printf. Signed-off-by: Marcos Maronas <[email protected]>
1 parent 52ba01c commit 569972a

10 files changed

+48
-111
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,18 @@ SPIRVType *LLVMToSPIRVBase::transSPIRVOpaqueType(StringRef STName,
831831
SPIRVType *LLVMToSPIRVBase::transScavengedType(Value *V) {
832832
if (auto *F = dyn_cast<Function>(V)) {
833833
FunctionType *FnTy = Scavenger->getFunctionType(F);
834+
// VarArg functions other than printf are not supported in SPIR-V. None of
835+
// printf variants can actually reach this point because they're skipped in
836+
// 'LLVMToSPIRVBase::translate()'. Specifically,
837+
// 'isBuiltinTransToExtInst(&F)' returns true for printf and its variants,
838+
// and so they are never added to 'Decls' and 'Defs'. Therefore, it's safe
839+
// to only check here if we're dealing with a variadic function to report an
840+
// error. To be on the safe side, an assertion is added to check printf
841+
// never reaches this point.
842+
assert(F->getName() != "printf");
843+
BM->getErrorLog().checkError(!FnTy->isVarArg(),
844+
SPIRVEC_UnsupportedVarArgFunction);
845+
834846
SPIRVType *RT = transType(FnTy->getReturnType());
835847
std::vector<SPIRVType *> PT;
836848
for (Argument &Arg : F->args()) {

lib/SPIRV/libSPIRV/SPIRVErrorEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ _SPIRV_OP(InvalidVersionNumber,
2929
"Invalid Version Number.")
3030
_SPIRV_OP(UnspecifiedMemoryModel, "Unspecified Memory Model.")
3131
_SPIRV_OP(RepeatedMemoryModel, "Expects a single OpMemoryModel instruction.")
32+
_SPIRV_OP(UnsupportedVarArgFunction,
33+
"Variadic functions other than 'printf' are not supported in SPIR-V.")
3234

3335
/* This is the last error code to have a maximum valid value to compare to */
3436
_SPIRV_OP(InternalMaxErrorCode, "Unknown error code")

test/DebugInfo/Generic/2009-11-10-CurrentFn.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ target triple = "spir64-unknown-unknown"
99

1010
define void @bar(i32 %i) nounwind uwtable ssp !dbg !5 {
1111
entry:
12-
tail call void (...) @foo() nounwind, !dbg !14
12+
tail call void @foo() nounwind, !dbg !14
1313
ret void, !dbg !16
1414
}
1515

16-
declare void @foo(...)
16+
declare void @foo()
1717

1818
declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone
1919

test/DebugInfo/Generic/multiline.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ target triple = "spir64-unknown-unknown"
4949
; Function Attrs: nounwind uwtable
5050
define void @f2() #0 !dbg !4 {
5151
entry:
52-
call void (...) @f1(), !dbg !11
53-
call void (...) @f1(), !dbg !12
54-
call void (...) @f1(), !dbg !13
55-
call void (...) @f1(), !dbg !14
56-
call void (...) @f1(), !dbg !15
57-
call void (...) @f1(), !dbg !16
52+
call void @f1(), !dbg !11
53+
call void @f1(), !dbg !12
54+
call void @f1(), !dbg !13
55+
call void @f1(), !dbg !14
56+
call void @f1(), !dbg !15
57+
call void @f1(), !dbg !16
5858
ret void, !dbg !17
5959
}
6060

61-
declare void @f1(...) #1
61+
declare void @f1() #1
6262

6363
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
6464
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

test/DebugInfo/Generic/varargs.ll

Lines changed: 0 additions & 94 deletions
This file was deleted.

test/DebugInfo/X86/abstract_origin.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ target triple = "spir64-unknown-unknown"
3030
; Function Attrs: alwaysinline nounwind ssp uwtable
3131
define void @g() #0 !dbg !7 {
3232
entry:
33-
tail call void (...) @f() #3, !dbg !10
33+
tail call void @f() #3, !dbg !10
3434
ret void, !dbg !11
3535
}
3636

37-
declare void @f(...)
37+
declare void @f()
3838

3939
; Function Attrs: nounwind ssp uwtable
4040
define void @h() #2 !dbg !12 {
4141
entry:
42-
tail call void (...) @f() #3, !dbg !13
42+
tail call void @f() #3, !dbg !13
4343
ret void, !dbg !15
4444
}
4545

test/DebugInfo/X86/dbg-value-const-byref.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ entry:
5151
call void @llvm.dbg.value(metadata i32 3, metadata !10, metadata !DIExpression()), !dbg !15
5252
%call = call i32 @f3(i32 3) #3, !dbg !16
5353
call void @llvm.dbg.value(metadata i32 7, metadata !10, metadata !DIExpression()), !dbg !18
54-
%call1 = call i32 (...) @f1() #3, !dbg !19
54+
%call1 = call i32 @f1() #3, !dbg !19
5555
call void @llvm.dbg.value(metadata i32 %call1, metadata !10, metadata !DIExpression()), !dbg !19
5656
store i32 %call1, ptr %i, align 4, !dbg !19, !tbaa !20
5757
call void @llvm.dbg.value(metadata ptr %i, metadata !10, metadata !DIExpression(DW_OP_deref)), !dbg !24
@@ -61,7 +61,7 @@ entry:
6161

6262
declare i32 @f3(i32)
6363

64-
declare i32 @f1(...)
64+
declare i32 @f1()
6565

6666
declare void @f2(ptr)
6767

test/DebugInfo/X86/single-dbg_value.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ target triple = "spir64-unknown-unknown"
4646
define void @f() #0 !dbg !4 {
4747
entry:
4848
tail call void @h(i32 0) #2, !dbg !14
49-
%call = tail call i32 (...) @g() #2, !dbg !15
49+
%call = tail call i32 @g() #2, !dbg !15
5050
tail call void @llvm.dbg.value(metadata i32 %call, metadata !8, metadata !16), !dbg !17
5151
tail call void @h(i32 %call) #2, !dbg !18
5252
ret void, !dbg !19
5353
}
5454

5555
declare void @h(i32)
5656

57-
declare i32 @g(...)
57+
declare i32 @g()
5858

5959
; Function Attrs: nounwind readnone
6060
declare void @llvm.dbg.value(metadata, metadata, metadata) #1

test/negative/unsup_invoke_instr.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ lpad:
3737
ret i32 0
3838
}
3939

40-
declare dso_local i32 @__gxx_personality_v0(...)
40+
declare dso_local i32 @__gxx_personality_v0()
4141

4242
attributes #0 = { norecurse "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="/localdisk2/icl/fadeeval/sycl_workspace/reproducer2/test.cpp" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
4343
attributes #1 = { norecurse nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; Check whether the translator reports an error for a
2+
; function other than printf with variadic arguments.
3+
4+
; RUN: llvm-as < %s -o %t.bc
5+
; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s
6+
7+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
8+
target triple = "spir64-unknown-unknown"
9+
10+
; CHECK: UnsupportedVarArgFunction: Variadic functions other than 'printf' are not supported in SPIR-V.
11+
; Function Attrs: convergent
12+
declare spir_func void @for__issue_diagnostic(i32 noundef, i32 noundef, ...) local_unnamed_addr
13+
14+
define i32 @foo() nounwind {
15+
call spir_func void (i32, i32, ...) @for__issue_diagnostic(i32 noundef 41, i32 noundef 0)
16+
ret i32 0
17+
}

0 commit comments

Comments
 (0)