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 | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 7 | |
| 8 | #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 9 | // expected-no-diagnostics |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 10 | #endif |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 11 | |
| 12 | // Test the -fdeclare-opencl-builtins option. |
| 13 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 14 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 15 | #if __OPENCL_C_VERSION__ < CL_VERSION_1_2 |
| 16 | #pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 17 | #endif |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 18 | |
Sven van Haastregt | af1c230 | 2019-06-19 12:48:22 +0000 | [diff] [blame] | 19 | // Provide typedefs when invoking clang without -finclude-default-header. |
| 20 | #ifdef NO_HEADER |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 21 | typedef char char2 __attribute__((ext_vector_type(2))); |
| 22 | typedef char char4 __attribute__((ext_vector_type(4))); |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 23 | typedef float float4 __attribute__((ext_vector_type(4))); |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 24 | typedef half half4 __attribute__((ext_vector_type(4))); |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 25 | typedef int int2 __attribute__((ext_vector_type(2))); |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 26 | typedef int int4 __attribute__((ext_vector_type(4))); |
| 27 | typedef long long2 __attribute__((ext_vector_type(2))); |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 28 | typedef unsigned char uchar; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 29 | typedef unsigned int uint; |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 30 | typedef unsigned long ulong; |
| 31 | typedef unsigned short ushort; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 32 | typedef __SIZE_TYPE__ size_t; |
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); |
| 42 | atom_cmpxchg((volatile __global unsigned int *)global_p, ui, ui); |
| 43 | } |
| 44 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 45 | kernel 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 Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 59 | char4 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 Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 65 | kernel 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 Haastregt | 2a69ed0 | 2019-09-25 09:12:59 +0000 | [diff] [blame] | 74 | |
| 75 | int imgWidth = get_image_width(image_read_only_image2d); |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 78 | #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 79 | kernel 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 Haastregt | 2a69ed0 | 2019-09-25 09:12:59 +0000 | [diff] [blame] | 84 | |
| 85 | int imgDepth = get_image_depth(image_read_write_image3d); |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 86 | } |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 87 | #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 88 | |
| 89 | kernel 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 Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 98 | kernel void basic_subgroup(global uint *out) { |
| 99 | out[0] = get_sub_group_size(); |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 100 | #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 Haastregt | 6c22eda | 2019-09-26 13:31:36 +0000 | [diff] [blame^] | 102 | // expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}} |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 103 | #endif |
| 104 | } |
| 105 | |
| 106 | kernel 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 | |
| 129 | kernel 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 Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 136 | } |