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