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 |
| 31 | |
| 32 | #ifdef _OPENCL_H_ |
| 33 | // expected-no-diagnostics |
| 34 | #endif |
| 35 | |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 36 | #ifdef FP64 |
| 37 | // expected-no-diagnostics |
| 38 | #endif |
| 39 | |
| 40 | #if __OPENCL_C_VERSION__ < 120 |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 41 | void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} |
| 42 | double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} |
| 43 | (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} |
| 44 | } |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 45 | #endif |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 46 | |
Konstantin Zhuravlyov | de70a88 | 2017-01-06 16:14:41 +0000 | [diff] [blame^] | 47 | #ifndef _OPENCL_H_ |
Neil Hickey | 7b5ddab | 2016-12-14 13:18:48 +0000 | [diff] [blame] | 48 | int isnan(float x) { |
| 49 | return __builtin_isnan(x); |
| 50 | } |
| 51 | |
| 52 | int isfinite(float x) { |
| 53 | return __builtin_isfinite(x); |
| 54 | } |
Konstantin Zhuravlyov | de70a88 | 2017-01-06 16:14:41 +0000 | [diff] [blame^] | 55 | #endif |
Neil Hickey | 7b5ddab | 2016-12-14 13:18:48 +0000 | [diff] [blame] | 56 | |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 57 | #pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 58 | #ifdef NOFP64 |
| 59 | // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} |
| 60 | #endif |
| 61 | |
Alexey Bader | 0ea0753 | 2016-11-01 15:50:52 +0000 | [diff] [blame] | 62 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
| 63 | #ifdef NOFP16 |
| 64 | // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}} |
| 65 | #endif |
| 66 | |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 67 | void f2(void) { |
| 68 | double d; |
| 69 | #ifdef NOFP64 |
| 70 | // expected-error@-2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}} |
| 71 | #endif |
| 72 | |
| 73 | (void) 1.0; |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 74 | |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 75 | #ifdef NOFP64 |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 76 | // 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] | 77 | #endif |
| 78 | } |
| 79 | |
| 80 | #pragma OPENCL EXTENSION cl_khr_fp64 : disable |
| 81 | #ifdef NOFP64 |
| 82 | // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} |
| 83 | #endif |
| 84 | |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 85 | #if __OPENCL_C_VERSION__ < 120 |
Yaxun Liu | 39cf40f | 2016-05-16 17:06:34 +0000 | [diff] [blame] | 86 | void f3(void) { |
| 87 | double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} |
| 88 | } |
Neil Hickey | 88c0fac | 2016-12-13 16:22:50 +0000 | [diff] [blame] | 89 | #endif |