| 1 |
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.0 |
| 2 |
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 |
| 3 |
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only -cl-std=CL1.1 -DNOPEDANTIC |
| 4 |
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 |
| 5 |
|
| 6 |
// Test with a target not supporting fp64. |
| 7 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16 |
| 8 |
// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16 |
| 9 |
// RUN: %clang_cc1 -cl-std=clc++2021 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16 |
| 10 |
|
| 11 |
// Test with some extensions enabled or disabled by cmd-line args |
| 12 |
// |
| 13 |
// Target does not support fp64 and fp16 - override it |
| 14 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+cl_khr_fp64,+cl_khr_fp16 |
| 15 |
// |
| 16 |
// Disable or enable all extensions |
| 17 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16 |
| 18 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all |
| 19 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64 |
| 20 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16 |
| 21 |
// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16 |
| 22 |
// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all -DFP64 |
| 23 |
// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64 |
| 24 |
// RUN: %clang_cc1 -cl-std=clc++2021 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16 |
| 25 |
// RUN: %clang_cc1 -cl-std=clc++2021 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all -DFP64 |
| 26 |
// RUN: %clang_cc1 -cl-std=clc++2021 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64 |
| 27 |
// |
| 28 |
// Concatenating |
| 29 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64 |
| 30 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64 |
| 31 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -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 |
| 32 |
// 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 |
| 33 |
// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -DFP64 |
| 34 |
// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,+__opencl_c_fp64,+cl_khr_fp64 -DFP64 |
| 35 |
// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64 |
| 36 |
// RUN: %clang_cc1 -cl-std=clc++2021 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -cl-ext=+__opencl_c_fp64,+cl_khr_fp64 -DFP64 |
| 37 |
// RUN: %clang_cc1 -cl-std=clc++2021 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,+__opencl_c_fp64,+cl_khr_fp64 -DFP64 |
| 38 |
// RUN: %clang_cc1 -cl-std=clc++2021 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 -DNOFP64 |
| 39 |
|
| 40 |
// Test with -finclude-default-header, which includes opencl-c.h. opencl-c.h |
| 41 |
// disables all extensions by default, but supported core extensions for a |
| 42 |
// particular OpenCL version must be re-enabled (for example, cl_khr_fp64 is |
| 43 |
// enabled by default with -cl-std=CL2.0). |
| 44 |
// |
| 45 |
// RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL2.0 -finclude-default-header |
| 46 |
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=clc++1.0 |
| 47 |
|
| 48 |
#ifdef _OPENCL_H_ |
| 49 |
// expected-no-diagnostics |
| 50 |
#endif |
| 51 |
|
| 52 |
#ifdef FP64 |
| 53 |
// expected-no-diagnostics |
| 54 |
#endif |
| 55 |
|
| 56 |
#if __OPENCL_CPP_VERSION__ == 100 |
| 57 |
// expected-no-diagnostics |
| 58 |
#endif |
| 59 |
|
| 60 |
#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120) |
| 61 |
void f1(double da) { |
| 62 |
#ifdef NOFP64 |
| 63 |
// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}} |
| 64 |
#elif !defined(NOPEDANTIC) |
| 65 |
// expected-warning@-4{{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}} |
| 66 |
#endif |
| 67 |
double d; |
| 68 |
#ifdef NOFP64 |
| 69 |
// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}} |
| 70 |
#elif !defined(NOPEDANTIC) |
| 71 |
// expected-warning@-4{{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}} |
| 72 |
#endif |
| 73 |
// FIXME: this diagnostic depends on the extension pragma in the earlier versions. |
| 74 |
// There is no indication that this behavior is expected. |
| 75 |
(void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} |
| 76 |
} |
| 77 |
#endif |
| 78 |
|
| 79 |
#ifndef _OPENCL_H_ |
| 80 |
int isnan(float x) { |
| 81 |
return __builtin_isnan(x); |
| 82 |
} |
| 83 |
|
| 84 |
int isfinite(float x) { |
| 85 |
return __builtin_isfinite(x); |
| 86 |
} |
| 87 |
#endif |
| 88 |
|
| 89 |
#pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 90 |
#ifdef NOFP64 |
| 91 |
// expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} |
| 92 |
#endif |
| 93 |
|
| 94 |
#pragma OPENCL EXTENSION cl_khr_fp16 : enable |
| 95 |
#ifdef NOFP16 |
| 96 |
// expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}} |
| 97 |
#endif |
| 98 |
|
| 99 |
void f2(void) { |
| 100 |
double d; |
| 101 |
#ifdef NOFP64 |
| 102 |
#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300) || __OPENCL_CPP_VERSION__ >= 202100) |
| 103 |
// expected-error@-3{{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}} |
| 104 |
#else |
| 105 |
// expected-error@-5{{use of type 'double' requires cl_khr_fp64 support}} |
| 106 |
#endif |
| 107 |
#endif |
| 108 |
|
| 109 |
typedef double double4 __attribute__((ext_vector_type(4))); |
| 110 |
double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f}; |
| 111 |
#ifdef NOFP64 |
| 112 |
#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300) || __OPENCL_CPP_VERSION__ >= 202100) |
| 113 |
// expected-error@-4 {{use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support}} |
| 114 |
#else |
| 115 |
// expected-error@-6 {{use of type 'double' requires cl_khr_fp64 support}} |
| 116 |
#endif |
| 117 |
#endif |
| 118 |
|
| 119 |
(void) 1.0; |
| 120 |
#ifdef NOFP64 |
| 121 |
#if ((defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 300) || __OPENCL_CPP_VERSION__ >= 202100) |
| 122 |
// expected-warning@-3{{double precision constant requires cl_khr_fp64 and __opencl_c_fp64, casting to single precision}} |
| 123 |
#else |
| 124 |
// expected-warning@-5{{double precision constant requires cl_khr_fp64, casting to single precision}} |
| 125 |
#endif |
| 126 |
#endif |
| 127 |
} |
| 128 |
|
| 129 |
#pragma OPENCL EXTENSION cl_khr_fp64 : disable |
| 130 |
#ifdef NOFP64 |
| 131 |
// expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} |
| 132 |
#endif |
| 133 |
|
| 134 |
#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120) |
| 135 |
void f3(void) { |
| 136 |
double d; |
| 137 |
#ifdef NOFP64 |
| 138 |
// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}} |
| 139 |
#elif !defined(NOPEDANTIC) |
| 140 |
// expected-warning@-4 {{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}} |
| 141 |
#endif |
| 142 |
} |
| 143 |
#endif |