Commit 4853031e by Marek Polacek Committed by Marek Polacek

re PR c/65830 (-Wno-shift-count-negative -Wno-shift-count-overflow don't work with const ints)

	PR c/65830
	* c-common.c (c_fully_fold_internal): Use OPT_Wshift_count_negative
	and OPT_Wshift_count_overflow.

	* c-c++-common/pr65830.c: New test.

From-SVN: r222407
parent b8787813
2015-04-24 Marek Polacek <polacek@redhat.com>
PR c/65830
* c-common.c (c_fully_fold_internal): Use OPT_Wshift_count_negative
and OPT_Wshift_count_overflow.
2015-04-24 Marek Polacek <polacek@redhat.com>
PR c/61534
* c-common.c (warn_logical_operator): Bail if either operand comes
from a macro expansion.
......
......@@ -1370,15 +1370,17 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
&& c_inhibit_evaluation_warnings == 0)
{
if (tree_int_cst_sgn (op1) < 0)
warning_at (loc, 0, (code == LSHIFT_EXPR
? G_("left shift count is negative")
: G_("right shift count is negative")));
warning_at (loc, OPT_Wshift_count_negative,
(code == LSHIFT_EXPR
? G_("left shift count is negative")
: G_("right shift count is negative")));
else if (compare_tree_int (op1,
TYPE_PRECISION (TREE_TYPE (orig_op0)))
>= 0)
warning_at (loc, 0, (code == LSHIFT_EXPR
? G_("left shift count >= width of type")
: G_("right shift count >= width of type")));
warning_at (loc, OPT_Wshift_count_overflow,
(code == LSHIFT_EXPR
? G_("left shift count >= width of type")
: G_("right shift count >= width of type")));
}
if ((code == TRUNC_DIV_EXPR
|| code == CEIL_DIV_EXPR
......
2015-04-24 Marek Polacek <polacek@redhat.com>
PR c/65830
* c-c++-common/pr65830.c: New test.
2015-04-24 Marek Polacek <polacek@redhat.com>
PR c/61534
* c-c++-common/pr61534-1.c: New test.
......
/* PR c/65830 */
/* { dg-do compile } */
/* { dg-options "-O -Wno-shift-count-negative -Wno-shift-count-overflow" } */
int
foo (int x)
{
const int a = sizeof (int) * __CHAR_BIT__;
const int b = -7;
int c = 0;
c += x << a; /* { dg-bogus "left shift count >= width of type" } */
c += x << b; /* { dg-bogus "left shift count is negative" } */
c += x >> a; /* { dg-bogus "right shift count >= width of type" } */
c += x >> b; /* { dg-bogus "right shift count is negative" } */
return c;
}
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