summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2016-04-22 22:14:32 +0000
committerRichard Trieu <rtrieu@google.com>2016-04-22 22:14:32 +0000
commit891f0f176ced7ad579a8c2afca2059c22f49093f (patch)
treee2a33747eb9ba7705140ada9a1992b869308735e
parent0b9531c8e643d63fad0c2b4f3e6738678c421c59 (diff)
downloadbcm5719-llvm-891f0f176ced7ad579a8c2afca2059c22f49093f.tar.gz
bcm5719-llvm-891f0f176ced7ad579a8c2afca2059c22f49093f.zip
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 llvm-svn: 267234
-rw-r--r--clang/include/clang/Basic/DiagnosticGroups.td6
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td7
-rw-r--r--clang/lib/Sema/SemaChecking.cpp16
-rw-r--r--clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp4
-rw-r--r--clang/test/SemaCXX/warn-float-conversion.cpp33
-rw-r--r--clang/test/SemaCXX/warn-literal-conversion.cpp11
6 files changed, 18 insertions, 59 deletions
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 487308293ad..8b5d8df6fc4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -49,12 +49,8 @@ def EnumConversion : DiagGroup<"enum-conversion">;
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">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 355892062b9..053dca3de89 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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">,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0592a830113..fb11adb4518 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -7403,13 +7403,8 @@ void DiagnoseFloatingImpCast(Sema &S, Expr *E, QualType T,
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, Expr *E, QualType T,
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) {
diff --git a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
index 022b3111b64..48c5b23207c 100644
--- a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
@@ -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
diff --git a/clang/test/SemaCXX/warn-float-conversion.cpp b/clang/test/SemaCXX/warn-float-conversion.cpp
index 5a5532572a8..fc221893aee 100644
--- a/clang/test/SemaCXX/warn-float-conversion.cpp
+++ b/clang/test/SemaCXX/warn-float-conversion.cpp
@@ -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;
diff --git a/clang/test/SemaCXX/warn-literal-conversion.cpp b/clang/test/SemaCXX/warn-literal-conversion.cpp
index 8a74166a019..875aa1dec5e 100644
--- a/clang/test/SemaCXX/warn-literal-conversion.cpp
+++ b/clang/test/SemaCXX/warn-literal-conversion.cpp
@@ -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;
+}
OpenPOWER on IntegriCloud