Skip to content

Commit f717479

Browse files
authored
Fix function with unused sret parameter (#2381)
Usually sret parameters are accessed by a memory instruction, from which would tell SPIRVTypeScavenger which type to use for this function parameter. But if sret parameter is unused later in the module scavenger would fail attempting to deduce type from the mangled name. Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent 64fe75e commit f717479

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/SPIRV/SPIRVTypeScavenger.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,8 @@ void SPIRVTypeScavenger::deduceFunctionType(Function &F) {
734734
for (Argument *Arg : PointerArgs) {
735735
if (auto *Ty =
736736
dyn_cast<TypedPointerType>(ParamTypes[Arg->getArgNo()]))
737-
TypeArgument(Arg, Ty);
737+
if (!Arg->hasAttribute(Attribute::StructRet))
738+
TypeArgument(Arg, Ty);
738739
}
739740
}
740741
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
3+
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
4+
; RUN: llvm-spirv %t.bc -o %t.spv
5+
; RUN: spirv-val %t.spv
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
8+
9+
; CHECK-SPIRV-DAG: Name [[#Fun:]] "_Z3booi"
10+
; CHECK-SPIRV-DAG: Decorate [[#Param:]] FuncParamAttr 3
11+
; CHECK-SPIRV-DAG: TypePointer [[#PtrTy:]] [[#]] [[#StructTy:]]
12+
; CHECK-SPIRV-DAG: TypeStruct [[#StructTy]]
13+
; CHECK-SPIRV: Function [[#]] [[#Fun]]
14+
; CHECK-SPIRV: FunctionParameter [[#PtrTy:]] [[#Param]]
15+
16+
; CHECK-LLVM: call spir_func void @_Z3booi(ptr sret(%struct.Example) align 8
17+
18+
source_filename = "/app/example.cpp"
19+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
20+
target triple = "spir-unknown-unknown"
21+
22+
%struct.Example = type { }
23+
24+
define spir_func i32 @foo() {
25+
%1 = alloca %struct.Example, align 8
26+
call void @_Z3booi(ptr sret(%struct.Example) align 8 %1, i32 noundef 42)
27+
ret i32 0
28+
}
29+
30+
declare void @_Z3booi(ptr sret(%struct.Example) align 8, i32 noundef)

0 commit comments

Comments
 (0)