This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Make -Wno-shift-count-negative -Wno-shift-count-overflow work for const ints (PR c/65830)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 22 Apr 2015 00:00:16 +0200
- Subject: [C PATCH] Make -Wno-shift-count-negative -Wno-shift-count-overflow work for const ints (PR c/65830)
- Authentication-results: sourceware.org; auth=none
A trivial patch to use OPT_* where they belong.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2015-04-21 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.
* c-c++-common/pr65830.c: New test.
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 7fe7fa6..64fc95f 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -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
diff --git gcc/testsuite/c-c++-common/pr65830.c gcc/testsuite/c-c++-common/pr65830.c
index e69de29..e115f18 100644
--- gcc/testsuite/c-c++-common/pr65830.c
+++ gcc/testsuite/c-c++-common/pr65830.c
@@ -0,0 +1,16 @@
+/* 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;
+}
Marek