Anastasia updated this revision to Diff 341833.
Anastasia added a comment.
- Added a pedantic warning about use of double even if the extension is in
disabled state wrt pragma.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100980/new/
https://reviews.llvm.org/D100980
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Misc/warning-flags.c
clang/test/SemaOpenCL/extensions.cl
Index: clang/test/SemaOpenCL/extensions.cl
===================================================================
--- clang/test/SemaOpenCL/extensions.cl
+++ clang/test/SemaOpenCL/extensions.cl
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only -cl-std=CL1.1 -DNOPEDANTIC
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64
// Test with a target not supporting fp64.
@@ -43,8 +44,20 @@
#endif
#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
-void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 support}}
- double d; // expected-error {{type 'double' requires cl_khr_fp64 support}}
+void f1(double da) {
+#ifdef NOFP64
+// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}}
+#elif !defined(NOPEDANTIC)
+// expected-warning@-4{{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}}
+#endif
+ double d;
+#ifdef NOFP64
+// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}}
+#elif !defined(NOPEDANTIC)
+// expected-warning@-4{{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}}
+#endif
+ // FIXME: this diagnostic depends on the extension pragma in the earlier versions.
+ // There is no indication that this behavior is expected.
(void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
}
#endif
@@ -79,13 +92,11 @@
double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
#ifdef NOFP64
// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 support}}
-// expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 support}}
#endif
(void) 1.0;
-
#ifdef NOFP64
-// expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}}
+// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}}
#endif
}
@@ -96,6 +107,11 @@
#if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
void f3(void) {
- double d; // expected-error {{type 'double' requires cl_khr_fp64 support}}
+ double d;
+#ifdef NOFP64
+// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}}
+#elif !defined(NOPEDANTIC)
+// expected-warning@-4 {{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}}
+#endif
}
#endif
Index: clang/test/Misc/warning-flags.c
===================================================================
--- clang/test/Misc/warning-flags.c
+++ clang/test/Misc/warning-flags.c
@@ -91,4 +91,4 @@
The list of warnings in -Wpedantic should NEVER grow.
-CHECK: Number in -Wpedantic (not covered by other -W flags): 26
+CHECK: Number in -Wpedantic (not covered by other -W flags): 27
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1524,6 +1524,13 @@
break;
case DeclSpec::TST_float: Result = Context.FloatTy; break;
case DeclSpec::TST_double:
+ if (S.getLangOpts().OpenCL) {
+ if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts()))
+ S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
+ << 0 << Context.DoubleTy << "cl_khr_fp64";
+ else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", S.getLangOpts()))
+ S.Diag(DS.getTypeSpecTypeLoc(), diag::ext_opencl_double_without_pragma);
+ }
if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long)
Result = Context.LongDoubleTy;
else
Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -365,7 +365,6 @@
}
}
- setOpenCLExtensionForType(Context.DoubleTy, "cl_khr_fp64");
#define GENERIC_IMAGE_TYPE_EXT(Type, Id, Ext) \
setOpenCLExtensionForType(Context.Id, Ext);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10003,6 +10003,8 @@
"invalid prototype, variadic arguments are not allowed in OpenCL">;
def err_opencl_requires_extension : Error<
"use of %select{type|declaration}0 %1 requires %2 support">;
+def ext_opencl_double_without_pragma : Extension<
+ "Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported">;
def warn_opencl_generic_address_space_arg : Warning<
"passing non-generic address space pointer to %0"
" may cause dynamic conversion affecting performance">,
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits