c-common.c (c_common_truthvalue_conversion): Warn for multiplications in boolean context.
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. From-SVN: r241490
This commit is contained in:
parent
1eb4547b10
commit
f834806177
|
@ -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>
|
2016-10-24 Martin Sebor <msebor@redhat.com>
|
||||||
|
|
||||||
PR middle-end/77735
|
PR middle-end/77735
|
||||||
|
|
|
@ -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>
|
2016-10-20 Bernd Edlinger <bernd.edlinger@hotmail.de>
|
||||||
|
|
||||||
* c-common.c (c_common_truthvalue_conversion): Fix the comment.
|
* c-common.c (c_common_truthvalue_conversion): Fix the comment.
|
||||||
|
|
|
@ -3327,6 +3327,11 @@ c_common_truthvalue_conversion (location_t location, tree expr)
|
||||||
return c_common_truthvalue_conversion (location,
|
return c_common_truthvalue_conversion (location,
|
||||||
TREE_OPERAND (expr, 0));
|
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:
|
case LSHIFT_EXPR:
|
||||||
/* We will only warn on signed shifts here, because the majority of
|
/* We will only warn on signed shifts here, because the majority of
|
||||||
false positive warnings happen in code where unsigned arithmetic
|
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
|
if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
|
||||||
&& !TYPE_UNSIGNED (TREE_TYPE (expr)))
|
&& !TYPE_UNSIGNED (TREE_TYPE (expr)))
|
||||||
warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
|
warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
|
||||||
"<< in boolean context, did you mean '<' ?");
|
"%<<<%> in boolean context, did you mean %<<%> ?");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COND_EXPR:
|
case COND_EXPR:
|
||||||
|
|
|
@ -6169,8 +6169,9 @@ of the C++ standard.
|
||||||
@opindex Wno-int-in-bool-context
|
@opindex Wno-int-in-bool-context
|
||||||
Warn for suspicious use of integer values where boolean values are expected,
|
Warn for suspicious use of integer values where boolean values are expected,
|
||||||
such as conditional expressions (?:) using non-boolean integer constants in
|
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{if (a <= b ? 2 : 3)}. Or left shifting of signed
|
||||||
boolean context, like @code{for (a = 0; 1 << a; a++);}.
|
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}.
|
This warning is enabled by @option{-Wall}.
|
||||||
|
|
||||||
@item -Wno-int-to-pointer-cast
|
@item -Wno-int-to-pointer-cast
|
||||||
|
|
|
@ -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>
|
2016-10-24 Martin Sebor <msebor@redhat.com>
|
||||||
|
|
||||||
PR middle-end/77735
|
PR middle-end/77735
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -1878,12 +1878,12 @@ stringop_block_profile (gimple *stmt, unsigned int *expected_align,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gcov_type count;
|
gcov_type count;
|
||||||
int alignment;
|
unsigned int alignment;
|
||||||
|
|
||||||
count = histogram->hvalue.counters[0];
|
count = histogram->hvalue.counters[0];
|
||||||
alignment = 1;
|
alignment = 1;
|
||||||
while (!(count & alignment)
|
while (!(count & alignment)
|
||||||
&& (alignment * 2 * BITS_PER_UNIT))
|
&& (alignment <= UINT_MAX / 2 / BITS_PER_UNIT))
|
||||||
alignment <<= 1;
|
alignment <<= 1;
|
||||||
*expected_align = alignment * BITS_PER_UNIT;
|
*expected_align = alignment * BITS_PER_UNIT;
|
||||||
gimple_remove_histogram_value (cfun, stmt, histogram);
|
gimple_remove_histogram_value (cfun, stmt, histogram);
|
||||||
|
|
Loading…
Reference in New Issue