]> granicus.if.org Git - clang/commitdiff
OpenCL: if double precision floating point constant encountered
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 11 Mar 2011 19:24:59 +0000 (19:24 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 11 Mar 2011 19:24:59 +0000 (19:24 +0000)
without cl_khr_fp64, warn and cast to single precision

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127476 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/SemaOpenCL/extension-fp64.cl

index 2331132507314fb62b4a58a59e785955e6f57abb..bac7050ae026d14da26af7160b5f38124122a5e7 100644 (file)
@@ -30,6 +30,8 @@ def warn_float_overflow : Warning<
 def warn_float_underflow : Warning<
   "magnitude of floating-point constant too small for type %0; minimum is %1">,
   InGroup<LiteralRange>;
+def warn_double_const_requires_fp64 : Warning<
+  "double precision constant requires cl_khr_fp64, casting to single precision">;
 
 // C99 variable-length arrays
 def ext_vla : Extension<
index 7dee50257d5a2d805b74850bc01aaabce9e05f20..8a532f0363d50b0be72bebf1480694a1a34e6b64 100644 (file)
@@ -2601,9 +2601,14 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
     bool isExact = (result == APFloat::opOK);
     Res = FloatingLiteral::Create(Context, Val, isExact, Ty, Tok.getLocation());
 
-    if (getLangOptions().SinglePrecisionConstants && Ty == Context.DoubleTy)
-      ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast);
-
+    if (Ty == Context.DoubleTy) {
+      if (getLangOptions().SinglePrecisionConstants) {
+        ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast);
+      } else if (getLangOptions().OpenCL && !getOpenCLOptions().cl_khr_fp64) {
+        Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64);
+        ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast);
+      }
+    }
   } else if (!Literal.isIntegerLiteral()) {
     return ExprError();
   } else {
index eaf2509502f2459fb452e8c5870852ba3e68b4c3..e0c2b1ea4b53df962076861f83b7706b97db23a0 100644 (file)
@@ -1,17 +1,19 @@
 // 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}}
+void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+  double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+  (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
 }
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
 void f2(void) {
   double d;
+  (void) 1.0;
 }
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : disable
 
 void f3(void) {
-  double d; // expected-error {{requires cl_khr_fp64 extension}}
+  double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
 }