blob: 6afb11e42a6a8156a1b98c38118747093bda8475 [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
31
32#ifdef _OPENCL_H_
33// expected-no-diagnostics
34#endif
35
Neil Hickey88c0fac2016-12-13 16:22:50 +000036#ifdef FP64
37// expected-no-diagnostics
38#endif
39
40#if __OPENCL_C_VERSION__ < 120
Yaxun Liu39cf40f2016-05-16 17:06:34 +000041void 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 Hickey88c0fac2016-12-13 16:22:50 +000045#endif
Yaxun Liu39cf40f2016-05-16 17:06:34 +000046
Konstantin Zhuravlyovde70a882017-01-06 16:14:41 +000047#ifndef _OPENCL_H_
Neil Hickey7b5ddab2016-12-14 13:18:48 +000048int isnan(float x) {
49 return __builtin_isnan(x);
50}
51
52int isfinite(float x) {
53 return __builtin_isfinite(x);
54}
Konstantin Zhuravlyovde70a882017-01-06 16:14:41 +000055#endif
Neil Hickey7b5ddab2016-12-14 13:18:48 +000056
Yaxun Liu39cf40f2016-05-16 17:06:34 +000057#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 Bader0ea07532016-11-01 15:50:52 +000062#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 Liu39cf40f2016-05-16 17:06:34 +000067void 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 Hickey88c0fac2016-12-13 16:22:50 +000074
Yaxun Liu39cf40f2016-05-16 17:06:34 +000075#ifdef NOFP64
Neil Hickey88c0fac2016-12-13 16:22:50 +000076// expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}}
Yaxun Liu39cf40f2016-05-16 17:06:34 +000077#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 Hickey88c0fac2016-12-13 16:22:50 +000085#if __OPENCL_C_VERSION__ < 120
Yaxun Liu39cf40f2016-05-16 17:06:34 +000086void f3(void) {
87 double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
88}
Neil Hickey88c0fac2016-12-13 16:22:50 +000089#endif