re PR c/65830 (-Wno-shift-count-negative -Wno-shift-count-overflow don't work with...
authorMarek Polacek <polacek@redhat.com>
Fri, 24 Apr 2015 11:53:27 +0000 (11:53 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 24 Apr 2015 11:53:27 +0000 (11:53 +0000)
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

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr65830.c [new file with mode: 0644]

index 270ef70e84839328d376b664e47c23e2e1f440ad..718aa2ad0a00cd58c2b7b82fbc87fa87d5e3a2bd 100644 (file)
@@ -1,3 +1,9 @@
+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
index b09bbb86f6f62ce0158c23b88ad67a3086a57c63..b8e141eb42fed2f088cec09ed9aeb0e624f409cf 100644 (file)
@@ -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
index c493bd83109dc235e19a6da302736e28992ad445..936a164a3a26892e5ba930436c8cb95117e42e29 100644 (file)
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/c-c++-common/pr65830.c b/gcc/testsuite/c-c++-common/pr65830.c
new file mode 100644 (file)
index 0000000..e115f18
--- /dev/null
@@ -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;
+}