Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report error when finding variadic function other than printf #2703

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,11 @@ SPIRVType *LLVMToSPIRVBase::transSPIRVOpaqueType(StringRef STName,
SPIRVType *LLVMToSPIRVBase::transScavengedType(Value *V) {
if (auto *F = dyn_cast<Function>(V)) {
FunctionType *FnTy = Scavenger->getFunctionType(F);
// VarArg functions other than printf are not supported in SPIR-V.
BM->getErrorLog().checkError(
!(FnTy->isVarArg() && F->getName() != "printf"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test too strict? In the test array_of_matrices.ll, I see:

declare dso_local spir_func i32 @_Z18__spirv_ocl_printfPU3AS2Kcz(ptr addrspace(2), ...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, there is mangling, and at least 3 names for the printf, so F->getName() != "printf" would not work properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered F->getName().contains("printf"), but thought that was too loose. What do you think, would that be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In SPIR-V Backend we have something along the lines of

  if ((DemangledName.starts_with("__spirv_ocl_printf(") ||
       DemangledName.starts_with("printf(")) ...

so I guess as a first approach this could work after you've got DemangledName from F->getName() from llvm::itaniumDemangle.

SPIRVEC_UnsupportedVarArgFunction);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

SPIRVType *RT = transType(FnTy->getReturnType());
std::vector<SPIRVType *> PT;
for (Argument &Arg : F->args()) {
Expand Down
2 changes: 2 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVErrorEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ _SPIRV_OP(InvalidVersionNumber,
"Invalid Version Number.")
_SPIRV_OP(UnspecifiedMemoryModel, "Unspecified Memory Model.")
_SPIRV_OP(RepeatedMemoryModel, "Expects a single OpMemoryModel instruction.")
_SPIRV_OP(UnsupportedVarArgFunction,
"Variadic functions other than 'printf' are not supported in SPIR-V.")

/* This is the last error code to have a maximum valid value to compare to */
_SPIRV_OP(InternalMaxErrorCode, "Unknown error code")
4 changes: 2 additions & 2 deletions test/DebugInfo/Generic/2009-11-10-CurrentFn.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ target triple = "spir64-unknown-unknown"

define void @bar(i32 %i) nounwind uwtable ssp !dbg !5 {
entry:
tail call void (...) @foo() nounwind, !dbg !14
tail call void @foo() nounwind, !dbg !14
ret void, !dbg !16
}

declare void @foo(...)
declare void @foo()

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

Expand Down
14 changes: 7 additions & 7 deletions test/DebugInfo/Generic/multiline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ target triple = "spir64-unknown-unknown"
; Function Attrs: nounwind uwtable
define void @f2() #0 !dbg !4 {
entry:
call void (...) @f1(), !dbg !11
call void (...) @f1(), !dbg !12
call void (...) @f1(), !dbg !13
call void (...) @f1(), !dbg !14
call void (...) @f1(), !dbg !15
call void (...) @f1(), !dbg !16
call void @f1(), !dbg !11
call void @f1(), !dbg !12
call void @f1(), !dbg !13
call void @f1(), !dbg !14
call void @f1(), !dbg !15
call void @f1(), !dbg !16
ret void, !dbg !17
}

declare void @f1(...) #1
declare void @f1() #1

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" }
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" }
Expand Down
94 changes: 0 additions & 94 deletions test/DebugInfo/Generic/varargs.ll

This file was deleted.

6 changes: 3 additions & 3 deletions test/DebugInfo/X86/abstract_origin.ll
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ target triple = "spir64-unknown-unknown"
; Function Attrs: alwaysinline nounwind ssp uwtable
define void @g() #0 !dbg !7 {
entry:
tail call void (...) @f() #3, !dbg !10
tail call void @f() #3, !dbg !10
ret void, !dbg !11
}

declare void @f(...)
declare void @f()

; Function Attrs: nounwind ssp uwtable
define void @h() #2 !dbg !12 {
entry:
tail call void (...) @f() #3, !dbg !13
tail call void @f() #3, !dbg !13
ret void, !dbg !15
}

Expand Down
4 changes: 2 additions & 2 deletions test/DebugInfo/X86/dbg-value-const-byref.ll
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ entry:
call void @llvm.dbg.value(metadata i32 3, metadata !10, metadata !DIExpression()), !dbg !15
%call = call i32 @f3(i32 3) #3, !dbg !16
call void @llvm.dbg.value(metadata i32 7, metadata !10, metadata !DIExpression()), !dbg !18
%call1 = call i32 (...) @f1() #3, !dbg !19
%call1 = call i32 @f1() #3, !dbg !19
call void @llvm.dbg.value(metadata i32 %call1, metadata !10, metadata !DIExpression()), !dbg !19
store i32 %call1, ptr %i, align 4, !dbg !19, !tbaa !20
call void @llvm.dbg.value(metadata ptr %i, metadata !10, metadata !DIExpression(DW_OP_deref)), !dbg !24
Expand All @@ -61,7 +61,7 @@ entry:

declare i32 @f3(i32)

declare i32 @f1(...)
declare i32 @f1()

declare void @f2(ptr)

Expand Down
4 changes: 2 additions & 2 deletions test/DebugInfo/X86/single-dbg_value.ll
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ target triple = "spir64-unknown-unknown"
define void @f() #0 !dbg !4 {
entry:
tail call void @h(i32 0) #2, !dbg !14
%call = tail call i32 (...) @g() #2, !dbg !15
%call = tail call i32 @g() #2, !dbg !15
tail call void @llvm.dbg.value(metadata i32 %call, metadata !8, metadata !16), !dbg !17
tail call void @h(i32 %call) #2, !dbg !18
ret void, !dbg !19
}

declare void @h(i32)

declare i32 @g(...)
declare i32 @g()

; Function Attrs: nounwind readnone
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
Expand Down
2 changes: 1 addition & 1 deletion test/negative/unsup_invoke_instr.ll
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lpad:
ret i32 0
}

declare dso_local i32 @__gxx_personality_v0(...)
declare dso_local i32 @__gxx_personality_v0()

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" }
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" }
Expand Down
20 changes: 20 additions & 0 deletions test/negative/unsupported_vararg_func.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; Check whether the translator reports an error for a
; function other than printf with variadic arguments.

; RUN: llvm-as < %s -o %t.bc
; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s

; ModuleID = 'unsupported_vararg_func.bc'
source_filename = "llvm-link"
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"
target triple = "spir64_x86_64"

; CHECK: UnsupportedVarArgFunction: Variadic functions other than 'printf' are not supported in SPIR-V.
; Function Attrs: convergent
declare spir_func void @for__issue_diagnostic(i32 noundef, i32 noundef, ...) local_unnamed_addr

define i32 @foo() nounwind {
call spir_func void (i32, i32, ...) @for__issue_diagnostic(i32 noundef 41, i32 noundef 0)
ret i32 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two spaces before ret :)

}

Loading