-
Notifications
You must be signed in to change notification settings - Fork 219
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
Changes from 4 commits
cc914c8
69b156f
4b20355
8a6d75f
87a6179
cbc9b10
7bef74e
13abd05
6d9585f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -814,6 +814,16 @@ 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. | ||
if (FnTy->isVarArg()) { | ||
StringRef DemangledName; | ||
oclIsBuiltin(F->getName(), DemangledName); | ||
BM->getErrorLog().checkError( | ||
(DemangledName.starts_with("printf(") || | ||
DemangledName.starts_with("__spirv_ocl_printf(")), | ||
SPIRVEC_UnsupportedVarArgFunction); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) { | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
; 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 | ||
|
||
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_unknown_unknown" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spir64-unknown-unknown |
||
|
||
; 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. two spaces before ret :) |
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oclIsBuiltin demangles "printf" to "__spirv_ocl_printf". I think only checking for: DemangledName.starts_with("__spirv_ocl_printf") should be sufficient. I think we should possibly be able to check for equality instead of starts_with.
Also does DemangledName include an open parenthesis?
oclIsBuiltin starts with:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have actually realized none of
printf
variants can reach this piece of code because they are skipped inSPIRV-LLVM-Translator/lib/SPIRV/SPIRVWriter.cpp
Line 5789 in 7dacb7c
isBuiltinTransToExtInst(&F)
returns true forprintf
, so it is just skipped and never added to neitherDecls
norDefs
. Considering this, I think we should be safe by just checking if the function is variadic to report the error at this point. What do you think? Also tagging the rest of approvers to gather their opinions: @svenvh @MrSidims @VyacheslavLevytskyy