blob: e9dba69ecd7c941b396744480b5612481ce49097 [file] [log] [blame]
Yaxun Liu39cf40f2016-05-16 17:06:34 +00001// 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 Hickey88c0fac2016-12-13 16:22:50 +00003// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64
Yaxun Liu39cf40f2016-05-16 17:06:34 +00004
5// Test with a target not supporting fp64.
Alexey Bader0ea07532016-11-01 15:50:52 +00006// 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 Zhuravlyovde70a882017-01-06 16:14:41 +000025// 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 Stulovabaa50632019-03-19 13:04:17 +000031// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=c++
Konstantin Zhuravlyovde70a882017-01-06 16:14:41 +000032
33#ifdef _OPENCL_H_
34// expected-no-diagnostics
35#endif
36
Neil Hickey88c0fac2016-12-13 16:22:50 +000037#ifdef FP64
38// expected-no-diagnostics
39#endif
40
Anastasia Stulovae88e2b92019-02-07 17:32:37 +000041#ifdef __OPENCL_CPP_VERSION__
42// expected-no-diagnostics
43#endif
44
45#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
Yaxun Liu39cf40f2016-05-16 17:06:34 +000046void 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 Hickey88c0fac2016-12-13 16:22:50 +000050#endif
Yaxun Liu39cf40f2016-05-16 17:06:34 +000051
Konstantin Zhuravlyovde70a882017-01-06 16:14:41 +000052#ifndef _OPENCL_H_
Neil Hickey7b5ddab2016-12-14 13:18:48 +000053int isnan(float x) {
54 return __builtin_isnan(x);
55}
56
57int isfinite(float x) {
58 return __builtin_isfinite(x);
59}
Konstantin Zhuravlyovde70a882017-01-06 16:14:41 +000060#endif
Neil Hickey7b5ddab2016-12-14 13:18:48 +000061
Yaxun Liu39cf40f2016-05-16 17:06:34 +000062#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 Bader0ea07532016-11-01 15:50:52 +000067#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 Liu39cf40f2016-05-16 17:06:34 +000072void 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 Sotkin73ae7cb2018-09-03 11:43:22 +000078 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 Liu39cf40f2016-05-16 17:06:34 +000085 (void) 1.0;
Neil Hickey88c0fac2016-12-13 16:22:50 +000086
Yaxun Liu39cf40f2016-05-16 17:06:34 +000087#ifdef NOFP64
Neil Hickey88c0fac2016-12-13 16:22:50 +000088// expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}}
Yaxun Liu39cf40f2016-05-16 17:06:34 +000089#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 Stulovae88e2b92019-02-07 17:32:37 +000097#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
Yaxun Liu39cf40f2016-05-16 17:06:34 +000098void f3(void) {
99 double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
100}
Neil Hickey88c0fac2016-12-13 16:22:50 +0000101#endif