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 | 0aed36d | 2019-11-01 13:56:43 +0000 | [diff] [blame] | 10 | #if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 11 | // expected-no-diagnostics |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 12 | #endif |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 13 | |
| 14 | // Test the -fdeclare-opencl-builtins option. |
| 15 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 16 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 17 | #if __OPENCL_C_VERSION__ < CL_VERSION_1_2 |
| 18 | #pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 19 | #endif |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 20 | |
Sven van Haastregt | af1c230 | 2019-06-19 12:48:22 +0000 | [diff] [blame] | 21 | // Provide typedefs when invoking clang without -finclude-default-header. |
| 22 | #ifdef NO_HEADER |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 23 | typedef unsigned char uchar; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 24 | typedef unsigned int uint; |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 25 | typedef unsigned long ulong; |
| 26 | typedef unsigned short ushort; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 27 | typedef __SIZE_TYPE__ size_t; |
Sven van Haastregt | 0e70c35 | 2019-11-06 11:53:19 +0000 | [diff] [blame^] | 28 | typedef char char2 __attribute__((ext_vector_type(2))); |
| 29 | typedef char char4 __attribute__((ext_vector_type(4))); |
| 30 | typedef uchar uchar4 __attribute__((ext_vector_type(4))); |
| 31 | typedef float float4 __attribute__((ext_vector_type(4))); |
| 32 | typedef half half4 __attribute__((ext_vector_type(4))); |
| 33 | typedef int int2 __attribute__((ext_vector_type(2))); |
| 34 | typedef int int4 __attribute__((ext_vector_type(4))); |
| 35 | typedef long long2 __attribute__((ext_vector_type(2))); |
Sven van Haastregt | af1c230 | 2019-06-19 12:48:22 +0000 | [diff] [blame] | 36 | #endif |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 37 | |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 38 | kernel void test_pointers(volatile global void *global_p, global const int4 *a) { |
| 39 | int i; |
| 40 | unsigned int ui; |
| 41 | |
| 42 | prefetch(a, 2); |
| 43 | |
| 44 | atom_add((volatile __global int *)global_p, i); |
| 45 | atom_cmpxchg((volatile __global unsigned int *)global_p, ui, ui); |
| 46 | } |
| 47 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 48 | kernel void basic_conversion() { |
| 49 | double d; |
| 50 | float f; |
| 51 | char2 c2; |
| 52 | long2 l2; |
| 53 | float4 f4; |
| 54 | int4 i4; |
| 55 | |
| 56 | f = convert_float(d); |
| 57 | d = convert_double_sat_rtp(f); |
| 58 | l2 = convert_long2_rtz(c2); |
| 59 | i4 = convert_int4_sat(f4); |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 62 | char4 test_int(char c, char4 c4) { |
| 63 | char m = max(c, c); |
| 64 | char4 m4 = max(c4, c4); |
Sven van Haastregt | 0e70c35 | 2019-11-06 11:53:19 +0000 | [diff] [blame^] | 65 | uchar4 abs1 = abs(c4); |
| 66 | uchar4 abs2 = abs(abs1); |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 67 | return max(c4, c); |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 70 | kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) { |
| 71 | int2 i2; |
| 72 | sampler_t sampler; |
| 73 | half4 res; |
| 74 | float4 resf; |
| 75 | |
| 76 | resf = read_imagef(image_read_only_image2d, i2); |
| 77 | res = read_imageh(image_read_only_image2d, i2); |
| 78 | res = read_imageh(image_read_only_image2d, sampler, i2); |
Sven van Haastregt | 2a69ed0 | 2019-09-25 09:12:59 +0000 | [diff] [blame] | 79 | |
| 80 | int imgWidth = get_image_width(image_read_only_image2d); |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 83 | #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 84 | kernel void basic_image_readwrite(read_write image3d_t image_read_write_image3d) { |
| 85 | half4 h4; |
| 86 | int4 i4; |
| 87 | |
| 88 | write_imageh(image_read_write_image3d, i4, h4); |
Sven van Haastregt | 2a69ed0 | 2019-09-25 09:12:59 +0000 | [diff] [blame] | 89 | |
| 90 | int imgDepth = get_image_depth(image_read_write_image3d); |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 91 | } |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 92 | #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 93 | |
| 94 | kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_image1d_buffer) { |
| 95 | half4 h4; |
| 96 | float4 f4; |
| 97 | int i; |
| 98 | |
| 99 | write_imagef(image_write_only_image1d_buffer, i, f4); |
| 100 | write_imageh(image_write_only_image1d_buffer, i, h4); |
| 101 | } |
| 102 | |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 103 | kernel void basic_subgroup(global uint *out) { |
| 104 | out[0] = get_sub_group_size(); |
Sven van Haastregt | 0aed36d | 2019-11-01 13:56:43 +0000 | [diff] [blame] | 105 | #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] | 106 | // 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] | 107 | // 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] | 108 | #endif |
| 109 | } |
| 110 | |
| 111 | kernel void basic_vector_data() { |
| 112 | #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
| 113 | generic void *generic_p; |
| 114 | #endif |
| 115 | constant void *constant_p; |
| 116 | local void *local_p; |
| 117 | global void *global_p; |
| 118 | private void *private_p; |
| 119 | size_t s; |
| 120 | |
| 121 | vload4(s, (const __constant ulong *) constant_p); |
| 122 | vload16(s, (const __constant short *) constant_p); |
| 123 | |
| 124 | #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 |
| 125 | vload3(s, (const __generic ushort *) generic_p); |
| 126 | vload16(s, (const __generic uchar *) generic_p); |
| 127 | #endif |
| 128 | |
| 129 | vload8(s, (const __global long *) global_p); |
| 130 | vload2(s, (const __local uint *) local_p); |
| 131 | vload16(s, (const __private float *) private_p); |
| 132 | } |
| 133 | |
| 134 | kernel void basic_work_item() { |
| 135 | uint ui; |
| 136 | |
| 137 | get_enqueued_local_size(ui); |
Sven van Haastregt | 0aed36d | 2019-11-01 13:56:43 +0000 | [diff] [blame] | 138 | #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] | 139 | // expected-error@-2{{implicit declaration of function 'get_enqueued_local_size' is invalid in OpenCL}} |
| 140 | #endif |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 141 | } |