[cfe-commits] r127476 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaOpenCL/extension-fp64.cl

Peter Collingbourne peter at pcc.me.uk
Fri Mar 11 11:24:59 PST 2011


Author: pcc
Date: Fri Mar 11 13:24:59 2011
New Revision: 127476

URL: http://llvm.org/viewvc/llvm-project?rev=127476&view=rev
Log:
OpenCL: if double precision floating point constant encountered
without cl_khr_fp64, warn and cast to single precision

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=127476&r1=127475&r2=127476&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Mar 11 13:24:59 2011
@@ -30,6 +30,8 @@
 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<

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=127476&r1=127475&r2=127476&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar 11 13:24:59 2011
@@ -2601,9 +2601,14 @@
     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 {

Modified: cfe/trunk/test/SemaOpenCL/extension-fp64.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extension-fp64.cl?rev=127476&r1=127475&r2=127476&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/extension-fp64.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extension-fp64.cl Fri Mar 11 13:24:59 2011
@@ -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}}
 }





More information about the cfe-commits mailing list