| 1 |
; This test checks that the translator doesn't crash if the module has literal |
| 2 |
; structs, i.e. structs whose type has no name. Typicaly clang generate such |
| 3 |
; structs if the kernel contains OpenCL 2.0 blocks. The IR was produced with |
| 4 |
; the following command: |
| 5 |
; clang -cc1 -triple spir -cl-std=cl2.0 -O0 literal-struct.cl -emit-llvm -o test/literal-struct.ll |
| 6 |
|
| 7 |
; literal-struct.cl: |
| 8 |
; void foo() |
| 9 |
; { |
| 10 |
; void (^myBlock)(void) = ^{}; |
| 11 |
; myBlock(); |
| 12 |
; } |
| 13 |
|
| 14 |
; RUN: llvm-as %s -o %t.bc |
| 15 |
; RUN: llvm-spirv %t.bc -spirv-text -o %t |
| 16 |
; RUN: FileCheck < %t %s |
| 17 |
; RUN: llvm-spirv %t.bc -o %t.spv |
| 18 |
; RUN: spirv-val %t.spv |
| 19 |
|
| 20 |
; CHECK: TypeInt [[Int:[0-9]+]] 32 0 |
| 21 |
; CHECK: TypeInt [[Int8:[0-9]+]] 8 0 |
| 22 |
; CHECK: TypePointer [[Int8Ptr:[0-9]+]] 8 [[Int8]] |
| 23 |
; CHECK: TypeStruct [[StructType:[0-9]+]] [[Int]] [[Int]] [[Int8Ptr]] |
| 24 |
|
| 25 |
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" |
| 26 |
target triple = "spir" |
| 27 |
|
| 28 |
%struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* } |
| 29 |
|
| 30 |
@__block_literal_global = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* @__foo_block_invoke to i8*) to i8 addrspace(4)*) }, align 4 |
| 31 |
; CHECK: ConstantComposite [[StructType]] |
| 32 |
|
| 33 |
@__block_literal_global.1 = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } zeroinitializer, align 4 |
| 34 |
; CHECK: ConstantNull [[StructType]] |
| 35 |
|
| 36 |
; Function Attrs: convergent noinline nounwind optnone |
| 37 |
define spir_func void @foo() #0 { |
| 38 |
entry: |
| 39 |
%myBlock = alloca %struct.__opencl_block_literal_generic addrspace(4)*, align 4 |
| 40 |
store %struct.__opencl_block_literal_generic addrspace(4)* addrspacecast (%struct.__opencl_block_literal_generic addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to %struct.__opencl_block_literal_generic addrspace(1)*) to %struct.__opencl_block_literal_generic addrspace(4)*), %struct.__opencl_block_literal_generic addrspace(4)** %myBlock, align 4 |
| 41 |
call spir_func void @__foo_block_invoke(i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global to i8 addrspace(1)*) to i8 addrspace(4)*)) #1 |
| 42 |
ret void |
| 43 |
} |
| 44 |
|
| 45 |
; Function Attrs: convergent noinline nounwind optnone |
| 46 |
define internal spir_func void @__foo_block_invoke(i8 addrspace(4)* %.block_descriptor) #0 { |
| 47 |
entry: |
| 48 |
%.block_descriptor.addr = alloca i8 addrspace(4)*, align 4 |
| 49 |
%block.addr = alloca <{ i32, i32, i8 addrspace(4)* }> addrspace(4)*, align 4 |
| 50 |
store i8 addrspace(4)* %.block_descriptor, i8 addrspace(4)** %.block_descriptor.addr, align 4 |
| 51 |
%block = bitcast i8 addrspace(4)* %.block_descriptor to <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* |
| 52 |
store <{ i32, i32, i8 addrspace(4)* }> addrspace(4)* %block, <{ i32, i32, i8 addrspace(4)* }> addrspace(4)** %block.addr, align 4 |
| 53 |
ret void |
| 54 |
} |
| 55 |
|
| 56 |
attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 57 |
attributes #1 = { convergent } |
| 58 |
|
| 59 |
!llvm.module.flags = !{!0} |
| 60 |
!opencl.ocl.version = !{!1} |
| 61 |
!opencl.spir.version = !{!1} |
| 62 |
!llvm.ident = !{!2} |
| 63 |
|
| 64 |
!0 = !{i32 1, !"wchar_size", i32 4} |
| 65 |
!1 = !{i32 2, i32 0} |
| 66 |
!2 = !{!"clang version 9.0.0 (https://llvm.org/git/clang 04fb8964a801a5c5d7baa5a22272243a7d183896) (https://llvm.org/git/llvm 384f64397f6ad95a361b72d62c07d7bac9f24163)"} |