extensions.cl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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
  3. // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64
  4. // Test with a target not supporting fp64.
  5. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
  6. // Test with some extensions enabled or disabled by cmd-line args
  7. //
  8. // Target does not support fp64 and fp16 - override it
  9. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+cl_khr_fp64,+cl_khr_fp16
  10. //
  11. // Disable or enable all extensions
  12. // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -DNOFP64 -DNOFP16
  13. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all
  14. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=+all,-cl_khr_fp64 -DNOFP64
  15. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -cl-ext=-all,+cl_khr_fp64 -DNOFP16
  16. //
  17. // Concatenating
  18. // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64 -cl-ext=+cl_khr_fp64
  19. // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-cl_khr_fp64,+cl_khr_fp64
  20. // 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
  21. // 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
  22. // Test with -finclude-default-header, which includes opencl-c.h. opencl-c.h
  23. // disables all extensions by default, but supported core extensions for a
  24. // particular OpenCL version must be re-enabled (for example, cl_khr_fp64 is
  25. // enabled by default with -cl-std=CL2.0).
  26. //
  27. // RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL2.0 -finclude-default-header
  28. // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=clc++
  29. #ifdef _OPENCL_H_
  30. // expected-no-diagnostics
  31. #endif
  32. #ifdef FP64
  33. // expected-no-diagnostics
  34. #endif
  35. #ifdef __OPENCL_CPP_VERSION__
  36. // expected-no-diagnostics
  37. #endif
  38. #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
  39. void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
  40. double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
  41. (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
  42. }
  43. #endif
  44. #ifndef _OPENCL_H_
  45. int isnan(float x) {
  46. return __builtin_isnan(x);
  47. }
  48. int isfinite(float x) {
  49. return __builtin_isfinite(x);
  50. }
  51. #endif
  52. #pragma OPENCL EXTENSION cl_khr_fp64 : enable
  53. #ifdef NOFP64
  54. // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
  55. #endif
  56. #pragma OPENCL EXTENSION cl_khr_fp16 : enable
  57. #ifdef NOFP16
  58. // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp16' - ignoring}}
  59. #endif
  60. void f2(void) {
  61. double d;
  62. #ifdef NOFP64
  63. // expected-error@-2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}}
  64. #endif
  65. typedef double double4 __attribute__((ext_vector_type(4)));
  66. double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
  67. #ifdef NOFP64
  68. // expected-error@-3 {{use of type 'double' requires cl_khr_fp64 extension to be enabled}}
  69. // expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled}}
  70. #endif
  71. (void) 1.0;
  72. #ifdef NOFP64
  73. // expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}}
  74. #endif
  75. }
  76. #pragma OPENCL EXTENSION cl_khr_fp64 : disable
  77. #ifdef NOFP64
  78. // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
  79. #endif
  80. #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
  81. void f3(void) {
  82. double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
  83. }
  84. #endif