Sven van Haastregt | 6c22eda | 2019-09-26 13:31:36 +0000 | [diff] [blame] | 1 | // 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 Haastregt | 0aed36d | 2019-11-01 13:56:43 +0000 | [diff] [blame] | 7 | // 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 Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 9 | |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 10 | // Test the -fdeclare-opencl-builtins option. |
| 11 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 12 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 13 | #if __OPENCL_C_VERSION__ < CL_VERSION_1_2 |
| 14 | #pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 15 | #endif |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 16 | |
Sven van Haastregt | af1c230 | 2019-06-19 12:48:22 +0000 | [diff] [blame] | 17 | // Provide typedefs when invoking clang without -finclude-default-header. |
| 18 | #ifdef NO_HEADER |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 19 | typedef unsigned char uchar; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 20 | typedef unsigned int uint; |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 21 | typedef unsigned long ulong; |
| 22 | typedef unsigned short ushort; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 23 | typedef __SIZE_TYPE__ size_t; |
Sven van Haastregt | 0e70c35 | 2019-11-06 11:53:19 +0000 | [diff] [blame] | 24 | typedef char char2 __attribute__((ext_vector_type(2))); |
| 25 | typedef char char4 __attribute__((ext_vector_type(4))); |
| 26 | typedef uchar uchar4 __attribute__((ext_vector_type(4))); |
| 27 | typedef float float4 __attribute__((ext_vector_type(4))); |
| 28 | typedef half half4 __attribute__((ext_vector_type(4))); |
| 29 | typedef int int2 __attribute__((ext_vector_type(2))); |
| 30 | typedef int int4 __attribute__((ext_vector_type(4))); |
Sven van Haastregt | e54c83e | 2019-11-26 10:44:49 +0000 | [diff] [blame] | 31 | typedef uint uint4 __attribute__((ext_vector_type(4))); |
Sven van Haastregt | 0e70c35 | 2019-11-06 11:53:19 +0000 | [diff] [blame] | 32 | typedef long long2 __attribute__((ext_vector_type(2))); |
Sven van Haastregt | af1c230 | 2019-06-19 12:48:22 +0000 | [diff] [blame] | 33 | #endif |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 34 | |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 35 | kernel 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 Haastregt | 308b8b7 | 2019-12-18 10:13:51 +0000 | [diff] [blame^] | 42 | #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 Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 56 | atom_cmpxchg((volatile __global unsigned int *)global_p, ui, ui); |
| 57 | } |
| 58 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 59 | kernel 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 Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 73 | char4 test_int(char c, char4 c4) { |
| 74 | char m = max(c, c); |
| 75 | char4 m4 = max(c4, c4); |
Sven van Haastregt | 0e70c35 | 2019-11-06 11:53:19 +0000 | [diff] [blame] | 76 | uchar4 abs1 = abs(c4); |
| 77 | uchar4 abs2 = abs(abs1); |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 78 | return max(c4, c); |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Sven van Haastregt | e54c83e | 2019-11-26 10:44:49 +0000 | [diff] [blame] | 81 | kernel 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 Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 88 | kernel 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 Haastregt | 2a69ed0 | 2019-09-25 09:12:59 +0000 | [diff] [blame] | 97 | |
| 98 | int imgWidth = get_image_width(image_read_only_image2d); |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 101 | #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 102 | kernel 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 Haastregt | 2a69ed0 | 2019-09-25 09:12:59 +0000 | [diff] [blame] | 107 | |
| 108 | int imgDepth = get_image_depth(image_read_write_image3d); |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 109 | } |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 110 | #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 111 | |
| 112 | kernel 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 Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 121 | kernel void basic_subgroup(global uint *out) { |
| 122 | out[0] = get_sub_group_size(); |
Sven van Haastregt | 0aed36d | 2019-11-01 13:56:43 +0000 | [diff] [blame] | 123 | #if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 124 | // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}} |
Sven van Haastregt | 6c22eda | 2019-09-26 13:31:36 +0000 | [diff] [blame] | 125 | // expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}} |
Sven van Haastregt | 308b8b7 | 2019-12-18 10:13:51 +0000 | [diff] [blame^] | 126 | #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 Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 131 | #endif |
| 132 | } |
| 133 | |
| 134 | kernel 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 | |
| 157 | kernel void basic_work_item() { |
| 158 | uint ui; |
| 159 | |
| 160 | get_enqueued_local_size(ui); |
Sven van Haastregt | 0aed36d | 2019-11-01 13:56:43 +0000 | [diff] [blame] | 161 | #if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 162 | // expected-error@-2{{implicit declaration of function 'get_enqueued_local_size' is invalid in OpenCL}} |
| 163 | #endif |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 164 | } |