Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only |
| 2 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 4 | |
| 5 | // Test with a target not supporting fp64. |
Alexey Bader | 0ea0753 | 2016-11-01 15:50:52 +0000 | [diff] [blame] | 6 | // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16 |
| 7 | |
| 8 | // Test with some extensions enabled or disabled by cmd-line args |
| 9 | // |
| 10 | // Target does not support fp64 and fp16 - override it |
| 11 | // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+cl_khr_fp64,+cl_khr_fp16 |
| 12 | // |
| 13 | // Disable or enable all extensions |
| 14 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16 |
| 15 | // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all |
| 16 | // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64 |
| 17 | // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16 |
| 18 | // |
| 19 | // Concatenating |
| 20 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64 |
| 21 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64 |
| 22 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64 |
| 23 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64 |
| 24 | |
Konstantin Zhuravlyov | de70a88 | 2017-01-06 16:14:41 +0000 | [diff] [blame] | 25 | // Test with -finclude-default-header, which includes opencl-c.h. opencl-c.h |
| 26 | // disables all extensions by default, but supported core extensions for a |
| 27 | // particular OpenCL version must be re-enabled (for example, cl_khr_fp64 is |
| 28 | // enabled by default with -cl-std=CL2.0). |
| 29 | // |
| 30 | // RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL2.0 -finclude-default-header |
Anastasia Stulova | baa5063 | 2019-03-19 13:04:17 +0000 | [diff] [blame] | 31 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=c++ |
Konstantin Zhuravlyov | de70a88 | 2017-01-06 16:14:41 +0000 | [diff] [blame] | 32 | |
| 33 | #ifdef _OPENCL_H_ |
| 34 | // expected-no-diagnostics |
| 35 | #endif |
| 36 | |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 37 | #ifdef FP64 |
| 38 | // expected-no-diagnostics |
| 39 | #endif |
| 40 | |
Anastasia Stulova | e88e2b9 | 2019-02-07 17:32:37 +0000 | [diff] [blame] | 41 | #ifdef __OPENCL_CPP_VERSION__ |
| 42 | // expected-no-diagnostics |
| 43 | #endif |
| 44 | |
| 45 | #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120) |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 46 | void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} |
| 47 | double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} |
| 48 | (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} |
| 49 | } |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 50 | #endif |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 51 | |
Konstantin Zhuravlyov | de70a88 | 2017-01-06 16:14:41 +0000 | [diff] [blame] | 52 | #ifndef _OPENCL_H_ |
Neil Hickey | 7b5ddab | 2016-12-14 13:18:48 +0000 | [diff] [blame] | 53 | int isnan(float x) { |
| 54 | return __builtin_isnan(x); |
| 55 | } |
| 56 | |
| 57 | int isfinite(float x) { |
| 58 | return __builtin_isfinite(x); |
| 59 | } |
Konstantin Zhuravlyov | de70a88 | 2017-01-06 16:14:41 +0000 | [diff] [blame] | 60 | #endif |
Neil Hickey | 7b5ddab | 2016-12-14 13:18:48 +0000 | [diff] [blame] | 61 | |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 62 | #pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 63 | #ifdef NOFP64 |
| 64 | // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} |
| 65 | #endif |
| 66 | |
Alexey Bader | 0ea0753 | 2016-11-01 15:50:52 +0000 | [diff] [blame] | 67 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
| 68 | #ifdef NOFP16 |
| 69 | // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}} |
| 70 | #endif |
| 71 | |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 72 | void f2(void) { |
| 73 | double d; |
| 74 | #ifdef NOFP64 |
| 75 | // expected-error@-2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}} |
| 76 | #endif |
| 77 | |
Alexey Sotkin | 73ae7cb | 2018-09-03 11:43:22 +0000 | [diff] [blame] | 78 | typedef double double4 __attribute__((ext_vector_type(4))); |
| 79 | double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f}; |
| 80 | #ifdef NOFP64 |
| 81 | // expected-error@-3 {{use of type 'double' requires cl_khr_fp64 extension to be enabled}} |
| 82 | // expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled}} |
| 83 | #endif |
| 84 | |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 85 | (void) 1.0; |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 86 | |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 87 | #ifdef NOFP64 |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 88 | // expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}} |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 89 | #endif |
| 90 | } |
| 91 | |
| 92 | #pragma OPENCL EXTENSION cl_khr_fp64 : disable |
| 93 | #ifdef NOFP64 |
| 94 | // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} |
| 95 | #endif |
| 96 | |
Anastasia Stulova | e88e2b9 | 2019-02-07 17:32:37 +0000 | [diff] [blame] | 97 | #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120) |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 98 | void f3(void) { |
| 99 | double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} |
| 100 | } |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 101 | #endif |