Skip to content

Commit

Permalink
[SPIRVToOCL20] Fix __spirv_ocl_printf translation assert error
Browse files Browse the repository at this point in the history
When SPIRVToOCL20Pass is used in OCL CPU backend to translate SPV-IR
builtin to OCL builtin, __spirv_ocl_printf call has bigger number of
arguments than its parameters.
  • Loading branch information
wenju-he committed Nov 28, 2024
1 parent da1731b commit 130a9b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/SPIRV/SPIRVBuiltinHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ BuiltinCallMutator::BuiltinCallMutator(BuiltinCallMutator &&Other)
Value *BuiltinCallMutator::doConversion() {
assert(CI && "Need to have a call instruction to do the conversion");
auto Mangler = makeMangler(CI, Rules);
for (unsigned I = 0; I < Args.size(); I++) {
for (unsigned I = 0, E = std::min(Args.size(), PointerTypes.size()); I < E;
I++) {
Mangler->getTypeMangleInfo(I).PointerTy =
dyn_cast<TypedPointerType>(PointerTypes[I]);
}
Expand Down
14 changes: 14 additions & 0 deletions test/printf-spv-ir-to-ocl.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; REQUIRES: pass-plugin
; UNSUPPORTED: target={{.*windows.*}}

; RUN: opt %load_spirv_lib -passes=spirv-to-ocl20 %s -S -o - | FileCheck %s

target triple = "spir64-unknown-unknown"

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

define spir_func void @__asan_set_shadow_dynamic_local() {
; CHECK: call spir_func i32 (ptr addrspace(2), ...) @printf(ptr addrspace(2) null, i32 0, i32 0)
%call = call spir_func i32 (ptr addrspace(2), ...) @_Z18__spirv_ocl_printfPU3AS2Kcz(ptr addrspace(2) null, i32 0, i32 0)
ret void
}

0 comments on commit 130a9b7

Please sign in to comment.