r267234 - Revert the bool portion of r267054

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 22 15:14:33 PDT 2016


Author: rtrieu
Date: Fri Apr 22 17:14:32 2016
New Revision: 267234

URL: http://llvm.org/viewvc/llvm-project?rev=267234&view=rev
Log:
Revert the bool portion of r267054

Remove the floating point to bool conversion warnings.  Some of these
conversions will be caught by -Wliteral-conversion and -Wfloat-conversion

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
    cfe/trunk/test/SemaCXX/warn-float-conversion.cpp
    cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=267234&r1=267233&r2=267234&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Apr 22 17:14:32 2016
@@ -49,12 +49,8 @@ def EnumConversion : DiagGroup<"enum-con
 
 def FloatOverflowConversion : DiagGroup<"float-overflow-conversion">;
 def FloatZeroConversion : DiagGroup<"float-zero-conversion">;
-def FloatBoolConstantConversion : DiagGroup<"float-bool-constant-conversion">;
-def FloatBoolConversion :
-  DiagGroup<"float-bool-conversion", [FloatBoolConstantConversion]>;
 def FloatConversion :
-  DiagGroup<"float-conversion", [FloatBoolConversion,
-                                 FloatOverflowConversion,
+  DiagGroup<"float-conversion", [FloatOverflowConversion,
                                  FloatZeroConversion]>;
 
 def DoublePromotion : DiagGroup<"double-promotion">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267234&r1=267233&r2=267234&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr 22 17:14:32 2016
@@ -2768,13 +2768,6 @@ def warn_impcast_float_integer : Warning
   "implicit conversion turns floating-point number into integer: %0 to %1">,
   InGroup<FloatConversion>, DefaultIgnore;
 
-def warn_impcast_float_bool : Warning<
-  "implicit conversion turns floating-point number into boolean: %0 to %1">,
-  InGroup<FloatBoolConversion>, DefaultIgnore;
-def warn_impcast_float_to_bool : Warning<
-  "implicit conversion from %0 to %1 changes value from %2 to %3">,
-  InGroup<FloatBoolConstantConversion>;
-
 def warn_impcast_float_to_integer : Warning<
   "implicit conversion of out of range value from %0 to %1 changes value "
   "from %2 to %3">,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=267234&r1=267233&r2=267234&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Apr 22 17:14:32 2016
@@ -7403,13 +7403,8 @@ void DiagnoseFloatingImpCast(Sema &S, Ex
   bool IsConstant =
     E->EvaluateAsFloat(Value, S.Context, Expr::SE_AllowSideEffects);
   if (!IsConstant) {
-    if (IsBool) {
-      return DiagnoseImpCast(S, E, T, CContext, diag::warn_impcast_float_bool,
-                             PruneWarnings);
-    } else {
-      return DiagnoseImpCast(S, E, T, CContext,
-                             diag::warn_impcast_float_integer, PruneWarnings);
-    }
+    return DiagnoseImpCast(S, E, T, CContext,
+                           diag::warn_impcast_float_integer, PruneWarnings);
   }
 
   bool isExact = false;
@@ -7418,17 +7413,14 @@ void DiagnoseFloatingImpCast(Sema &S, Ex
                             T->hasUnsignedIntegerRepresentation());
   if (Value.convertToInteger(IntegerValue, llvm::APFloat::rmTowardZero,
                              &isExact) == llvm::APFloat::opOK &&
-      isExact && !IsBool) {
+      isExact) {
     if (IsLiteral) return;
     return DiagnoseImpCast(S, E, T, CContext, diag::warn_impcast_float_integer,
                            PruneWarnings);
   }
 
   unsigned DiagID = 0;
-  if (IsBool) {
-    // Warn on all floating point to bool conversions
-    DiagID = diag::warn_impcast_float_to_bool;
-  } else if (IsLiteral) {
+  if (IsLiteral) {
     // Warn on floating point literal to integer.
     DiagID = diag::warn_impcast_literal_float_to_integer;
   } else if (IntegerValue == 0) {

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp?rev=267234&r1=267233&r2=267234&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp Fri Apr 22 17:14:32 2016
@@ -58,8 +58,8 @@ void float_to_int() {
   Agg<char> ce1 = { Convert<float>(1.0) }; // expected-error {{type 'float' cannot be narrowed to 'char'}} expected-note {{silence}}
   Agg<char> ce2 = { ConvertVar<double>() }; // expected-error {{type 'double' cannot be narrowed to 'char'}} expected-note {{silence}}
 
-  bool b{1.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}} expected-warning {{changes value}}
-  Agg<bool> ab = {0.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}} expected-warning {{changes value}}
+  bool b{1.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}}
+  Agg<bool> ab = {0.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}}
 }
 
 // * from long double to double or float, or from double to float, except where

Modified: cfe/trunk/test/SemaCXX/warn-float-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-float-conversion.cpp?rev=267234&r1=267233&r2=267234&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-float-conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-float-conversion.cpp Fri Apr 22 17:14:32 2016
@@ -1,8 +1,6 @@
 // RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-literal-conversion -Wfloat-conversion -DFLOAT_CONVERSION -DZERO -DBOOL -DCONSTANT_BOOL -DOVERFLOW
 // RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-conversion -Wfloat-overflow-conversion -DOVERFLOW
 // RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-conversion -Wfloat-zero-conversion -DZERO
-// RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-conversion -Wfloat-bool-constant-conversion -DCONSTANT_BOOL
-// RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-conversion -Wfloat-bool-conversion -DCONSTANT_BOOL -DBOOL
 
 float ReturnFloat();
 
@@ -68,37 +66,6 @@ void TestConstantFloat() {
 }
 #endif  // FLOAT_CONVERSION
 
-#ifdef CONSTANT_BOOL
-const float pi = 3.1415;
-
-void TestConstantBool() {
-  bool b1 = 0.99f; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 0.99 to true}}
-  bool b2 = 0.99; // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 0.99 to true}}
-  bool b3 = 0.0f; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 0 to false}}
-  bool b4 = 0.0; // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 0 to false}}
-  bool b5 = 1.0f; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 1 to true}}
-  bool b6 = 1.0; // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 1 to true}}
-  bool b7 = pi; // expected-warning {{implicit conversion from 'const float' to 'bool' changes value from 3.1415 to true}}
-  bool b8 = pi - pi; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 0 to false}}
-}
-#endif  // CONSTANT_BOOL
-
-#ifdef BOOL
-const float E = 2.718;
-
-float GetFloat();
-double GetDouble();
-
-void TestBool() {
-  bool b1 = GetFloat(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'float' to 'bool'}}
-  bool b2 = GetDouble(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'double' to 'bool'}}
-  bool b3 = 0.0 * GetDouble(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'double' to 'bool'}}
-  bool b4 = GetFloat() + GetDouble(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'double' to 'bool'}}
-  bool b5 = E + GetFloat(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'float' to 'bool'}}
-}
-
-#endif  // BOOL
-
 #ifdef ZERO
 void TestZero() {
   const float half = .5;

Modified: cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp?rev=267234&r1=267233&r2=267234&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-literal-conversion.cpp Fri Apr 22 17:14:32 2016
@@ -38,3 +38,14 @@ void test0() {
   int y = (24*60*60) * 0.25;
   int pennies = 123.45 * 100;
 }
+
+// Similarly, test floating point conversion to bool. Only float values of zero
+// are converted to false; everything else is converted to true.
+void test1() {
+  bool b1 = 0.99f; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 0.99 to true}}
+  bool b2 = 0.99; // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 0.99 to true}}
+  // These do not warn because they can be directly converted to integral
+  // values.
+  bool b3 = 0.0f;
+  bool b4 = 0.0;
+}




More information about the cfe-commits mailing list