]> granicus.if.org Git - clang/commitdiff
OpenCL: semantic analysis support for cl_khr_fp64 extension
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 15 Feb 2011 19:46:23 +0000 (19:46 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 15 Feb 2011 19:46:23 +0000 (19:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125588 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaType.cpp
test/CMakeLists.txt
test/SemaOpenCL/extension-fp64.cl [new file with mode: 0644]

index 272ca6892ab9d69e8e695c9e0553cd0f1528150c..81b66812cfbbbcfe613c5b6b56b112674eb430ec 100644 (file)
@@ -3635,6 +3635,8 @@ def ext_c99_array_usage : Extension<
   "use of C99-specific array features, accepted as an extension">;
 def err_c99_array_usage_cxx : Error<
   "C99-specific array features are not permitted in C++">;
+def err_double_requires_fp64 : Error<
+  "use of type 'double' requires cl_khr_fp64 extension to be enabled">;
   
 def note_getter_unavailable : Note<
   "or because setter is declared here, but no getter method %0 is found">;
index b6d28cbe719273dc5e057ba922d830eb6c772798..e69f9dd176295c15e3100c2cd198bda4101fb67e 100644 (file)
@@ -671,6 +671,11 @@ static QualType ConvertDeclSpecToType(Sema &S, TypeProcessingState &state) {
       Result = Context.LongDoubleTy;
     else
       Result = Context.DoubleTy;
+
+    if (S.getLangOptions().OpenCL && !S.getOpenCLOptions().cl_khr_fp64) {
+      S.Diag(DS.getTypeSpecTypeLoc(), diag::err_double_requires_fp64);
+      declarator.setInvalidType(true);
+    }
     break;
   case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool
   case DeclSpec::TST_decimal32:    // _Decimal32
index da9ca218cd5f71d1080c3c0233fc47f45839c399..02b6c9b81379ae76b05fd6af7e8df863062fabd2 100644 (file)
@@ -23,6 +23,7 @@ set(CLANG_TEST_DIRECTORIES
   "SemaCXX"
   "SemaObjC"
   "SemaObjCXX"
+  "SemaOpenCL"
   "SemaTemplate")
 
 set(LLVM_SOURCE_DIR "${LLVM_MAIN_SRC_DIR}")
diff --git a/test/SemaOpenCL/extension-fp64.cl b/test/SemaOpenCL/extension-fp64.cl
new file mode 100644 (file)
index 0000000..eaf2509
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+void f1(double da) { // expected-error {{requires cl_khr_fp64 extension}}
+  double d; // expected-error {{requires cl_khr_fp64 extension}}
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+void f2(void) {
+  double d;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : disable
+
+void f3(void) {
+  double d; // expected-error {{requires cl_khr_fp64 extension}}
+}