summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoredlinger <edlinger@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-24 17:14:41 +0000
committeredlinger <edlinger@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-24 17:14:41 +0000
commit5f64e688ee4e2d5c421c8c46bb6f80588db58368 (patch)
tree192f2356af6a042207d630b08e779de14912326f
parentc62d63d43bbf00c88cefcd2f71f8d5c6adafd294 (diff)
downloadgcc-5f64e688ee4e2d5c421c8c46bb6f80588db58368.tar.gz
2016-10-24 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-common.c (c_common_truthvalue_conversion): Warn for multiplications in boolean context. Fix the quoting of '<<' and '<' in the shift warning. gcc: 2016-10-24 Bernd Edlinger <bernd.edlinger@hotmail.de> * doc/invoke.text (Wint-in-bool-context): Update documentation. * value-prof.c (stringop_block_profile): Fix a warning. testsuite: 2016-10-24 Bernd Edlinger <bernd.edlinger@hotmail.de> * c-c++-common/Wint-in-bool-context-3.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241490 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-common.c7
-rw-r--r--gcc/doc/invoke.texi5
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/c-c++-common/Wint-in-bool-context-3.c15
-rw-r--r--gcc/value-prof.c4
7 files changed, 41 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a8528b91c41..1f6712e6144 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-24 Bernd Edlinger <bernd.edlinger@hotmail.de>
+
+ * doc/invoke.text (Wint-in-bool-context): Update documentation.
+ * value-prof.c (stringop_block_profile): Fix a warning.
+
2016-10-24 Martin Sebor <msebor@redhat.com>
PR middle-end/77735
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index b16b1c1fac4..6a6dba28593 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2016-10-24 Bernd Edlinger <bernd.edlinger@hotmail.de>
+
+ * c-common.c (c_common_truthvalue_conversion): Warn for
+ multiplications in boolean context. Fix the quoting of '<<' and '<'
+ in the shift warning.
+
2016-10-20 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-common.c (c_common_truthvalue_conversion): Fix the comment.
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index abc07402640..c0dafc08652 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3327,6 +3327,11 @@ c_common_truthvalue_conversion (location_t location, tree expr)
return c_common_truthvalue_conversion (location,
TREE_OPERAND (expr, 0));
+ case MULT_EXPR:
+ warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
+ "%<*%> in boolean context, suggest %<&&%> instead");
+ break;
+
case LSHIFT_EXPR:
/* We will only warn on signed shifts here, because the majority of
false positive warnings happen in code where unsigned arithmetic
@@ -3336,7 +3341,7 @@ c_common_truthvalue_conversion (location_t location, tree expr)
if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
&& !TYPE_UNSIGNED (TREE_TYPE (expr)))
warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
- "<< in boolean context, did you mean '<' ?");
+ "%<<<%> in boolean context, did you mean %<<%> ?");
break;
case COND_EXPR:
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 9f57d52d516..5ccd4244ef3 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6169,8 +6169,9 @@ of the C++ standard.
@opindex Wno-int-in-bool-context
Warn for suspicious use of integer values where boolean values are expected,
such as conditional expressions (?:) using non-boolean integer constants in
-boolean context, like @code{if (a <= b ? 2 : 3)}. Or left shifting in
-boolean context, like @code{for (a = 0; 1 << a; a++);}.
+boolean context, like @code{if (a <= b ? 2 : 3)}. Or left shifting of signed
+integers in boolean context, like @code{for (a = 0; 1 << a; a++);}. Likewise
+for all kinds of multiplications regardless of the data type.
This warning is enabled by @option{-Wall}.
@item -Wno-int-to-pointer-cast
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 28c755036d8..5b83f4de125 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2016-10-24 Bernd Edlinger <bernd.edlinger@hotmail.de>
+
+ * c-c++-common/Wint-in-bool-context-3.c: New test.
+
2016-10-24 Martin Sebor <msebor@redhat.com>
PR middle-end/77735
diff --git a/gcc/testsuite/c-c++-common/Wint-in-bool-context-3.c b/gcc/testsuite/c-c++-common/Wint-in-bool-context-3.c
new file mode 100644
index 00000000000..869132a90c3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wint-in-bool-context-3.c
@@ -0,0 +1,15 @@
+/* { dg-options "-Wint-in-bool-context" } */
+/* { dg-do compile } */
+
+#define BITS_PER_UNIT 8
+
+int foo (int count)
+{
+ int alignment;
+
+ alignment = 1;
+ while (!(count & alignment)
+ && (alignment * 2 * BITS_PER_UNIT)) /* { dg-warning "boolean context" } */
+ alignment <<= 1;
+ return alignment * BITS_PER_UNIT;
+}
diff --git a/gcc/value-prof.c b/gcc/value-prof.c
index e794e6d5aef..dc570692fbf 100644
--- a/gcc/value-prof.c
+++ b/gcc/value-prof.c
@@ -1878,12 +1878,12 @@ stringop_block_profile (gimple *stmt, unsigned int *expected_align,
else
{
gcov_type count;
- int alignment;
+ unsigned int alignment;
count = histogram->hvalue.counters[0];
alignment = 1;
while (!(count & alignment)
- && (alignment * 2 * BITS_PER_UNIT))
+ && (alignment <= UINT_MAX / 2 / BITS_PER_UNIT))
alignment <<= 1;
*expected_align = alignment * BITS_PER_UNIT;
gimple_remove_histogram_value (cfun, stmt, histogram);