r289650 - Fixing cast condition for removing casts from builtin FPClassification.

Neil Hickey via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 14 05:18:48 PST 2016


Author: neil.hickey
Date: Wed Dec 14 07:18:48 2016
New Revision: 289650

URL: http://llvm.org/viewvc/llvm-project?rev=289650&view=rev
Log:
Fixing cast condition for removing casts from builtin FPClassification.

The function SemaBuiltinFPClassification removed superfluous float to double 
casts, this was changed to also remove float to float casts but this isn't 
valid in all cases, for example when doing an rvaluetolvalue cast. Added a
check to only remove if this was a conventional floating cast.

Added additional tests into SemaOpenCL/extensions to cover these cases


Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaOpenCL/extensions.cl

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=289650&r1=289649&r2=289650&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Dec 14 07:18:48 2016
@@ -3750,13 +3750,16 @@ bool Sema::SemaBuiltinFPClassification(C
 
   // If this is an implicit conversion from float -> float or double, remove it.
   if (ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(OrigArg)) {
-    Expr *CastArg = Cast->getSubExpr();
-    if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) {
-        assert((Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) ||
-                Cast->getType()->isSpecificBuiltinType(BuiltinType::Float)) &&
-             "promotion from float to either float or double is the only expected cast here");
-      Cast->setSubExpr(nullptr);
-      TheCall->setArg(NumArgs-1, CastArg);
+    // Only remove standard FloatCasts, leaving other casts inplace
+    if (Cast->getCastKind() == CK_FloatingCast) {
+      Expr *CastArg = Cast->getSubExpr();
+      if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) {
+          assert((Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) ||
+                  Cast->getType()->isSpecificBuiltinType(BuiltinType::Float)) &&
+               "promotion from float to either float or double is the only expected cast here");
+        Cast->setSubExpr(nullptr);
+        TheCall->setArg(NumArgs-1, CastArg);
+      }
     }
   }
   

Modified: cfe/trunk/test/SemaOpenCL/extensions.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extensions.cl?rev=289650&r1=289649&r2=289650&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/extensions.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extensions.cl Wed Dec 14 07:18:48 2016
@@ -35,6 +35,14 @@ void f1(double da) { // expected-error {
 }
 #endif
 
+int isnan(float x) {
+    return __builtin_isnan(x);
+}
+
+int isfinite(float x) {
+    return __builtin_isfinite(x);
+}
+
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 #ifdef NOFP64
 // expected-warning at -2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}




More information about the cfe-commits mailing list