blob: 250a3f008c9429b6fe49cec5c8cd29dc9b718750 [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 Haastregted69faa2019-09-19 13:41:51 +00007
8#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
Sven van Haastregtb21a3652019-08-19 11:56:03 +00009// expected-no-diagnostics
Sven van Haastregted69faa2019-09-19 13:41:51 +000010#endif
Sven van Haastregt79a222f2019-06-03 09:39:11 +000011
12// Test the -fdeclare-opencl-builtins option.
13
Sven van Haastregt988f1e32019-09-05 10:01:24 +000014#pragma OPENCL EXTENSION cl_khr_fp16 : enable
Sven van Haastregted69faa2019-09-19 13:41:51 +000015#if __OPENCL_C_VERSION__ < CL_VERSION_1_2
16#pragma OPENCL EXTENSION cl_khr_fp64 : enable
17#endif
Sven van Haastregt988f1e32019-09-05 10:01:24 +000018
Sven van Haastregtaf1c2302019-06-19 12:48:22 +000019// Provide typedefs when invoking clang without -finclude-default-header.
20#ifdef NO_HEADER
Sven van Haastregtb21a3652019-08-19 11:56:03 +000021typedef char char2 __attribute__((ext_vector_type(2)));
22typedef char char4 __attribute__((ext_vector_type(4)));
Sven van Haastregt79a222f2019-06-03 09:39:11 +000023typedef float float4 __attribute__((ext_vector_type(4)));
Sven van Haastregt988f1e32019-09-05 10:01:24 +000024typedef half half4 __attribute__((ext_vector_type(4)));
Sven van Haastregt79a222f2019-06-03 09:39:11 +000025typedef int int2 __attribute__((ext_vector_type(2)));
Sven van Haastregtb21a3652019-08-19 11:56:03 +000026typedef int int4 __attribute__((ext_vector_type(4)));
27typedef long long2 __attribute__((ext_vector_type(2)));
Sven van Haastregted69faa2019-09-19 13:41:51 +000028typedef unsigned char uchar;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000029typedef unsigned int uint;
Sven van Haastregted69faa2019-09-19 13:41:51 +000030typedef unsigned long ulong;
31typedef unsigned short ushort;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000032typedef __SIZE_TYPE__ size_t;
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);
42 atom_cmpxchg((volatile __global unsigned int *)global_p, ui, ui);
43}
44
Sven van Haastregtb21a3652019-08-19 11:56:03 +000045kernel void basic_conversion() {
46 double d;
47 float f;
48 char2 c2;
49 long2 l2;
50 float4 f4;
51 int4 i4;
52
53 f = convert_float(d);
54 d = convert_double_sat_rtp(f);
55 l2 = convert_long2_rtz(c2);
56 i4 = convert_int4_sat(f4);
Sven van Haastregt79a222f2019-06-03 09:39:11 +000057}
58
Sven van Haastregtb21a3652019-08-19 11:56:03 +000059char4 test_int(char c, char4 c4) {
60 char m = max(c, c);
61 char4 m4 = max(c4, c4);
62 return max(c4, c);
Sven van Haastregt79a222f2019-06-03 09:39:11 +000063}
64
Sven van Haastregt988f1e32019-09-05 10:01:24 +000065kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) {
66 int2 i2;
67 sampler_t sampler;
68 half4 res;
69 float4 resf;
70
71 resf = read_imagef(image_read_only_image2d, i2);
72 res = read_imageh(image_read_only_image2d, i2);
73 res = read_imageh(image_read_only_image2d, sampler, i2);
Sven van Haastregt2a69ed02019-09-25 09:12:59 +000074
75 int imgWidth = get_image_width(image_read_only_image2d);
Sven van Haastregt988f1e32019-09-05 10:01:24 +000076}
77
Sven van Haastregted69faa2019-09-19 13:41:51 +000078#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
Sven van Haastregt988f1e32019-09-05 10:01:24 +000079kernel void basic_image_readwrite(read_write image3d_t image_read_write_image3d) {
80 half4 h4;
81 int4 i4;
82
83 write_imageh(image_read_write_image3d, i4, h4);
Sven van Haastregt2a69ed02019-09-25 09:12:59 +000084
85 int imgDepth = get_image_depth(image_read_write_image3d);
Sven van Haastregt988f1e32019-09-05 10:01:24 +000086}
Sven van Haastregted69faa2019-09-19 13:41:51 +000087#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
Sven van Haastregt988f1e32019-09-05 10:01:24 +000088
89kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_image1d_buffer) {
90 half4 h4;
91 float4 f4;
92 int i;
93
94 write_imagef(image_write_only_image1d_buffer, i, f4);
95 write_imageh(image_write_only_image1d_buffer, i, h4);
96}
97
Sven van Haastregt79a222f2019-06-03 09:39:11 +000098kernel void basic_subgroup(global uint *out) {
99 out[0] = get_sub_group_size();
Sven van Haastregted69faa2019-09-19 13:41:51 +0000100#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
101// expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
Sven van Haastregt6c22eda2019-09-26 13:31:36 +0000102// expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000103#endif
104}
105
106kernel void basic_vector_data() {
107#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
108 generic void *generic_p;
109#endif
110 constant void *constant_p;
111 local void *local_p;
112 global void *global_p;
113 private void *private_p;
114 size_t s;
115
116 vload4(s, (const __constant ulong *) constant_p);
117 vload16(s, (const __constant short *) constant_p);
118
119#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
120 vload3(s, (const __generic ushort *) generic_p);
121 vload16(s, (const __generic uchar *) generic_p);
122#endif
123
124 vload8(s, (const __global long *) global_p);
125 vload2(s, (const __local uint *) local_p);
126 vload16(s, (const __private float *) private_p);
127}
128
129kernel void basic_work_item() {
130 uint ui;
131
132 get_enqueued_local_size(ui);
133#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
134// expected-error@-2{{implicit declaration of function 'get_enqueued_local_size' is invalid in OpenCL}}
135#endif
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000136}