Skip to content

Commit c1828a9

Browse files
authored
[SPIRVToOCL20] Fix __spirv_ocl_printf translation assert error (#2891)
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.
1 parent 8af0eb5 commit c1828a9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/SPIRV/SPIRVBuiltinHelper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ BuiltinCallMutator::BuiltinCallMutator(BuiltinCallMutator &&Other)
9090
Value *BuiltinCallMutator::doConversion() {
9191
assert(CI && "Need to have a call instruction to do the conversion");
9292
auto Mangler = makeMangler(CI, Rules);
93-
for (unsigned I = 0; I < Args.size(); I++) {
93+
for (unsigned I = 0, E = std::min(Args.size(), PointerTypes.size()); I < E;
94+
I++) {
9495
Mangler->getTypeMangleInfo(I).PointerTy =
9596
dyn_cast<TypedPointerType>(PointerTypes[I]);
9697
}

test/printf-spv-ir-to-ocl.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; REQUIRES: pass-plugin
2+
; UNSUPPORTED: target={{.*windows.*}}
3+
4+
; RUN: opt %load_spirv_lib -passes=spirv-to-ocl20 %s -S -o - | FileCheck %s
5+
6+
target triple = "spir64-unknown-unknown"
7+
8+
declare spir_func i32 @_Z18__spirv_ocl_printfPU3AS2Kcz(ptr addrspace(2), ...)
9+
10+
define spir_func void @__asan_set_shadow_dynamic_local() {
11+
; CHECK: call spir_func i32 (ptr addrspace(2), ...) @printf(ptr addrspace(2) null, i32 0, i32 0)
12+
%call = call spir_func i32 (ptr addrspace(2), ...) @_Z18__spirv_ocl_printfPU3AS2Kcz(ptr addrspace(2) null, i32 0, i32 0)
13+
ret void
14+
}

0 commit comments

Comments
 (0)