Commit 4c712374 by Bernd Edlinger

c-common.c (c_common_truthvalue_conversion): Warn only for signed integer shift…

c-common.c (c_common_truthvalue_conversion): Warn only for signed integer shift ops in boolean context.

2016-10-19  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * c-common.c (c_common_truthvalue_conversion): Warn only for signed
        integer shift ops in boolean context.

testsuite:
2016-10-19  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * c-c++-common/Wint-in-bool-context-2.c: New test.

From-SVN: r241354
parent f3070dab
2016-06-16 Aldy Hernandez <aldyh@redhat.com> 2016-10-19 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-common.c (c_common_truthvalue_conversion): Warn only for signed
integer shift ops in boolean context.
2016-10-18 Aldy Hernandez <aldyh@redhat.com>
* c.opt (Walloca): New. * c.opt (Walloca): New.
(Walloca-larger-than=): New. (Walloca-larger-than=): New.
......
...@@ -3328,6 +3328,13 @@ c_common_truthvalue_conversion (location_t location, tree expr) ...@@ -3328,6 +3328,13 @@ c_common_truthvalue_conversion (location_t location, tree expr)
TREE_OPERAND (expr, 0)); TREE_OPERAND (expr, 0));
case LSHIFT_EXPR: case LSHIFT_EXPR:
/* We will only warn on unsigned shifts here, because the majority of
false positive warnings happen in code where unsigned arithmetic
was used in anticipation of a possible overflow.
Furthermore, if we see an unsigned type here we know that the
result of the shift is not subject to integer promotion rules. */
if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
&& !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;
......
2016-10-19 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-c++-common/Wint-in-bool-context-2.c: New test.
2016-10-19 Jerry DeLisle <jvdelisle@gcc.gnu.org> 2016-10-19 Jerry DeLisle <jvdelisle@gcc.gnu.org>
* gfortran.dg/dtio_17.f90: Fix test. * gfortran.dg/dtio_17.f90: Fix test.
......
/* { dg-options "-Wint-in-bool-context" } */
/* { dg-do compile } */
typedef unsigned u32;
typedef unsigned char u8;
#define KEYLENGTH 8
int foo (u8 plen, u32 key)
{
if ((plen < KEYLENGTH) && (key << plen)) /* { dg-bogus "boolean context" } */
return -1;
if ((plen << KEYLENGTH) && (key < plen)) /* { dg-warning "boolean context" } */
return -2;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment