blob: 000f96278faaa2b738395fc5a7b5a7aea13f27c5 [file] [log] [blame]
Sven van Haastregt6c22eda2019-09-26 13:31:36 +00001// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
2// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
3// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
4// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
5// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
6// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
Sven van Haastregt0aed36d2019-11-01 13:56:43 +00007// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -DNO_HEADER
8// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -finclude-default-header
Sven van Haastregted69faa2019-09-19 13:41:51 +00009
Sven van Haastregt79a222f2019-06-03 09:39:11 +000010// Test the -fdeclare-opencl-builtins option.
11
Sven van Haastregt988f1e32019-09-05 10:01:24 +000012#pragma OPENCL EXTENSION cl_khr_fp16 : enable
Sven van Haastregted69faa2019-09-19 13:41:51 +000013#if __OPENCL_C_VERSION__ < CL_VERSION_1_2
14#pragma OPENCL EXTENSION cl_khr_fp64 : enable
15#endif
Sven van Haastregt988f1e32019-09-05 10:01:24 +000016
Sven van Haastregtaf1c2302019-06-19 12:48:22 +000017// Provide typedefs when invoking clang without -finclude-default-header.
18#ifdef NO_HEADER
Sven van Haastregted69faa2019-09-19 13:41:51 +000019typedef unsigned char uchar;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000020typedef unsigned int uint;
Sven van Haastregted69faa2019-09-19 13:41:51 +000021typedef unsigned long ulong;
22typedef unsigned short ushort;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000023typedef __SIZE_TYPE__ size_t;
Sven van Haastregt0e70c352019-11-06 11:53:19 +000024typedef char char2 __attribute__((ext_vector_type(2)));
25typedef char char4 __attribute__((ext_vector_type(4)));
26typedef uchar uchar4 __attribute__((ext_vector_type(4)));
27typedef float float4 __attribute__((ext_vector_type(4)));
28typedef half half4 __attribute__((ext_vector_type(4)));
29typedef int int2 __attribute__((ext_vector_type(2)));
30typedef int int4 __attribute__((ext_vector_type(4)));
Sven van Haastregte54c83e2019-11-26 10:44:49 +000031typedef uint uint4 __attribute__((ext_vector_type(4)));
Sven van Haastregt0e70c352019-11-06 11:53:19 +000032typedef long long2 __attribute__((ext_vector_type(2)));
Sven van Haastregtaf1c2302019-06-19 12:48:22 +000033#endif
Sven van Haastregt79a222f2019-06-03 09:39:11 +000034
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000035kernel void test_pointers(volatile global void *global_p, global const int4 *a) {
36 int i;
37 unsigned int ui;
38
39 prefetch(a, 2);
40
41 atom_add((volatile __global int *)global_p, i);
Sven van Haastregt308b8b72019-12-18 10:13:51 +000042#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_1_1
43// expected-error@-2{{no matching function for call to 'atom_add'}}
44
45// There are two potential definitions of the function "atom_add", both are
46// currently disabled because the associated extension is disabled.
47// expected-note@-6{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}}
48// expected-note@-7{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}}
49#endif
50
51#if __OPENCL_C_VERSION__ < CL_VERSION_1_1
52#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable
53#endif
54
55 atom_add((volatile __global int *)global_p, i);
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000056 atom_cmpxchg((volatile __global unsigned int *)global_p, ui, ui);
57}
58
Sven van Haastregtb21a3652019-08-19 11:56:03 +000059kernel void basic_conversion() {
60 double d;
61 float f;
62 char2 c2;
63 long2 l2;
64 float4 f4;
65 int4 i4;
66
67 f = convert_float(d);
68 d = convert_double_sat_rtp(f);
69 l2 = convert_long2_rtz(c2);
70 i4 = convert_int4_sat(f4);
Sven van Haastregt79a222f2019-06-03 09:39:11 +000071}
72
Sven van Haastregtb21a3652019-08-19 11:56:03 +000073char4 test_int(char c, char4 c4) {
74 char m = max(c, c);
75 char4 m4 = max(c4, c4);
Sven van Haastregt0e70c352019-11-06 11:53:19 +000076 uchar4 abs1 = abs(c4);
77 uchar4 abs2 = abs(abs1);
Sven van Haastregtb21a3652019-08-19 11:56:03 +000078 return max(c4, c);
Sven van Haastregt79a222f2019-06-03 09:39:11 +000079}
80
Sven van Haastregte54c83e2019-11-26 10:44:49 +000081kernel void basic_vector_misc(float4 a) {
82 float4 res;
83 uint4 mask = (uint4)(1, 2, 3, 4);
84
85 res = shuffle(a, mask);
86}
87
Sven van Haastregt988f1e32019-09-05 10:01:24 +000088kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) {
89 int2 i2;
90 sampler_t sampler;
91 half4 res;
92 float4 resf;
93
94 resf = read_imagef(image_read_only_image2d, i2);
95 res = read_imageh(image_read_only_image2d, i2);
96 res = read_imageh(image_read_only_image2d, sampler, i2);
Sven van Haastregt2a69ed02019-09-25 09:12:59 +000097
98 int imgWidth = get_image_width(image_read_only_image2d);
Sven van Haastregt988f1e32019-09-05 10:01:24 +000099}
100
Sven van Haastregted69faa2019-09-19 13:41:51 +0000101#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000102kernel void basic_image_readwrite(read_write image3d_t image_read_write_image3d) {
103 half4 h4;
104 int4 i4;
105
106 write_imageh(image_read_write_image3d, i4, h4);
Sven van Haastregt2a69ed02019-09-25 09:12:59 +0000107
108 int imgDepth = get_image_depth(image_read_write_image3d);
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000109}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000110#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000111
112kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_image1d_buffer) {
113 half4 h4;
114 float4 f4;
115 int i;
116
117 write_imagef(image_write_only_image1d_buffer, i, f4);
118 write_imageh(image_write_only_image1d_buffer, i, h4);
119}
120
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000121kernel void basic_subgroup(global uint *out) {
122 out[0] = get_sub_group_size();
Sven van Haastregt0aed36d2019-11-01 13:56:43 +0000123#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
Sven van Haastregted69faa2019-09-19 13:41:51 +0000124// expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
Sven van Haastregt6c22eda2019-09-26 13:31:36 +0000125// expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}}
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000126#elif defined(__OPENCL_CPP_VERSION__)
127// expected-error@-5{{no matching function for call to 'get_sub_group_size'}}
128// expected-note@-6{{candidate unavailable as it requires OpenCL extension 'cl_khr_subgroups' to be enabled}}
129#else
130// expected-error@-8{{use of declaration 'get_sub_group_size' requires cl_khr_subgroups extension to be enabled}}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000131#endif
132}
133
134kernel void basic_vector_data() {
135#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
136 generic void *generic_p;
137#endif
138 constant void *constant_p;
139 local void *local_p;
140 global void *global_p;
141 private void *private_p;
142 size_t s;
143
144 vload4(s, (const __constant ulong *) constant_p);
145 vload16(s, (const __constant short *) constant_p);
146
147#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
148 vload3(s, (const __generic ushort *) generic_p);
149 vload16(s, (const __generic uchar *) generic_p);
150#endif
151
152 vload8(s, (const __global long *) global_p);
153 vload2(s, (const __local uint *) local_p);
154 vload16(s, (const __private float *) private_p);
155}
156
157kernel void basic_work_item() {
158 uint ui;
159
160 get_enqueued_local_size(ui);
Sven van Haastregt0aed36d2019-11-01 13:56:43 +0000161#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
Sven van Haastregted69faa2019-09-19 13:41:51 +0000162// expected-error@-2{{implicit declaration of function 'get_enqueued_local_size' is invalid in OpenCL}}
163#endif
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000164}