blob: 2433c17fe02226afe67f302a88c5322f88c316fa [file] [log] [blame]
Yaxun Liu39cf40f2016-05-16 17:06:34 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown
Matt Arsenaultefb38192013-07-23 01:23:36 +00002
Yaxun Liu042acb22016-09-19 17:11:22 +00003kernel void half_arg(half x) { } // expected-error{{declaring function parameter of type 'half' is not allowed; did you forget * ?}}
4
Matt Arsenaultefb38192013-07-23 01:23:36 +00005#pragma OPENCL EXTENSION cl_khr_fp16 : enable
6
7
8// Disallowed: parameters with type
9// bool, half, size_t, ptrdiff_t, intptr_t, and uintptr_t
10// or a struct / union with any of these types in them
11
12// TODO: Ban int types, size_t, ptrdiff_t ...
13
14kernel void bool_arg(bool x) { } // expected-error{{'bool' cannot be used as the type of a kernel parameter}}
15
Yaxun Liu042acb22016-09-19 17:11:22 +000016// half kernel argument is allowed when cl_khr_fp16 is enabled.
17kernel void half_arg(half x) { }
Matt Arsenaultefb38192013-07-23 01:23:36 +000018
19typedef struct ContainsBool // expected-note{{within field of type 'ContainsBool' declared here}}
20{
21 bool x; // expected-note{{field of illegal type 'bool' declared here}}
22} ContainsBool;
23
24kernel void bool_in_struct_arg(ContainsBool x) { } // expected-error{{'ContainsBool' (aka 'struct ContainsBool') cannot be used as the type of a kernel parameter}}
25
26
27
28typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}}
29{
Anastasia Stulova1f95cc02016-03-03 13:33:19 +000030 // TODO: Clean up needed - we don't really need to check for image, event, etc
31 // as a note here any longer.
32 // They are diagnosed as an error for all struct fields (OpenCL v1.2 s6.9b,r).
Alexey Bader954ba212016-04-08 13:40:33 +000033 image2d_t imageField; // expected-note{{field of illegal type '__read_only image2d_t' declared here}} expected-error{{the '__read_only image2d_t' type cannot be used to declare a structure or union field}}
Matt Arsenaultefb38192013-07-23 01:23:36 +000034} FooImage2D;
35
36kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}}
37
38typedef struct Foo // expected-note{{within field of type 'Foo' declared here}}
39{
40 int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}}
41} Foo;
42
43kernel void pointer_in_struct_arg(Foo arg) { } // expected-error{{struct kernel parameters may not contain pointers}}
44
45typedef union FooUnion // expected-note{{within field of type 'FooUnion' declared here}}
46{
47 int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}}
48} FooUnion;
49
50kernel void pointer_in_union_arg(FooUnion arg) { }// expected-error{{union kernel parameters may not contain pointers}}
51
52typedef struct NestedPointer // expected-note 2 {{within field of type 'NestedPointer' declared here}}
53{
54 int x;
55 struct InnerNestedPointer
56 {
57 int* ptrField; // expected-note 3 {{field of illegal pointer type 'int *' declared here}}
58 } inner; // expected-note 3 {{within field of type 'struct InnerNestedPointer' declared here}}
59} NestedPointer;
60
61kernel void pointer_in_nested_struct_arg(NestedPointer arg) { }// expected-error{{struct kernel parameters may not contain pointers}}
62
63struct NestedPointerComplex // expected-note{{within field of type 'NestedPointerComplex' declared here}}
64{
65 int foo;
66 float bar;
67
68 struct InnerNestedPointerComplex
69 {
70 int innerFoo;
71 int* innerPtrField; // expected-note{{field of illegal pointer type 'int *' declared here}}
72 } inner; // expected-note{{within field of type 'struct InnerNestedPointerComplex' declared here}}
73
74 float y;
75 float z[4];
76};
77
78kernel void pointer_in_nested_struct_arg_complex(struct NestedPointerComplex arg) { }// expected-error{{struct kernel parameters may not contain pointers}}
79
80typedef struct NestedBool // expected-note 2 {{within field of type 'NestedBool' declared here}}
81{
82 int x;
83 struct InnerNestedBool
84 {
85 bool boolField; // expected-note 2 {{field of illegal type 'bool' declared here}}
86 } inner; // expected-note 2 {{within field of type 'struct InnerNestedBool' declared here}}
87} NestedBool;
88
89kernel void bool_in_nested_struct_arg(NestedBool arg) { } // expected-error{{'NestedBool' (aka 'struct NestedBool') cannot be used as the type of a kernel parameter}}
90
91// Warning emitted again for argument used in other kernel
92kernel void bool_in_nested_struct_arg_again(NestedBool arg) { } // expected-error{{'NestedBool' (aka 'struct NestedBool') cannot be used as the type of a kernel parameter}}
93
94
95// Check for note with a struct not defined inside the struct
96typedef struct NestedBool2Inner
97{
98 bool boolField; // expected-note{{field of illegal type 'bool' declared here}}
99} NestedBool2Inner;
100
101typedef struct NestedBool2 // expected-note{{within field of type 'NestedBool2' declared here}}
102{
103 int x;
104 NestedBool2Inner inner; // expected-note{{within field of type 'NestedBool2Inner' (aka 'struct NestedBool2Inner') declared here}}
105} NestedBool2;
106
107kernel void bool_in_nested_struct_2_arg(NestedBool2 arg) { } // expected-error{{'NestedBool2' (aka 'struct NestedBool2') cannot be used as the type of a kernel parameter}}
108
109
110struct InnerInner
111{
112 int* foo;
113 bool x;
114};
115
116struct Valid
117{
118 float c;
119 float d;
120};
121
122struct Inner
123{
124 struct Valid v;
125 struct InnerInner a;
126 struct Valid g;
127 struct InnerInner b;
128};
129
130struct AlsoUser // expected-note{{within field of type 'AlsoUser' declared here}}
131{
132 float x;
133 struct Valid valid1;
134 struct Valid valid2;
135 struct NestedPointer aaaa; // expected-note{{within field of type 'struct NestedPointer' declared here}}
136};
137
138kernel void pointer_in_nested_struct_arg_2(struct Valid valid, struct NestedPointer arg, struct AlsoUser also) { } // expected-error 2 {{struct kernel parameters may not contain pointers}}