]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix #52283 error: case label does not reduce to an integer constant
authorChristian Bruel <chrbr@gcc.gnu.org>
Thu, 19 Apr 2012 09:06:53 +0000 (11:06 +0200)
committerChristian Bruel <chrbr@gcc.gnu.org>
Thu, 19 Apr 2012 09:06:53 +0000 (11:06 +0200)
From-SVN: r186586

gcc/ChangeLog
gcc/c-family/c-common.c
gcc/convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr37985.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr52283.c [new file with mode: 0644]

index f2a9e0ae29fc7f77cec5cd8dcb796f381d09bdd0..7f3d9ac6b9a767d98a2e5ca82ae190bc42ab091e 100644 (file)
@@ -1,3 +1,9 @@
+2012-04-19   Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c/52283/37985
+       * stmt.c (warn_if_unused_value): Skip NOP_EXPR.
+       * convert.c (convert_to_integer): Don't set TREE_NO_WARNING.
+
 2012-04-19  Richard Guenther  <rguenther@suse.de>
 
        PR rtl-optimization/44688
index a08db464dfd4a88fb280c05cf763162192b77b5e..339eefeea84a3f1b0a3ffedff8dc6e2adf76d532 100644 (file)
@@ -1692,6 +1692,7 @@ warn_if_unused_value (const_tree exp, location_t locus)
 
     case SAVE_EXPR:
     case NON_LVALUE_EXPR:
+    case NOP_EXPR:
       exp = TREE_OPERAND (exp, 0);
       goto restart;
 
index 8ff2e9a825af8e144f1867ac8c2e343ece19681b..5e6b09e06545805374c87b117b9a2f1057d4e392 100644 (file)
@@ -537,7 +537,6 @@ convert_to_integer (tree type, tree expr)
       else if (outprec >= inprec)
        {
          enum tree_code code;
-         tree tem;
 
          /* If the precision of the EXPR's type is K bits and the
             destination mode has more bits, and the sign is changing,
@@ -555,13 +554,7 @@ convert_to_integer (tree type, tree expr)
          else
            code = NOP_EXPR;
 
-         tem = fold_unary (code, type, expr);
-         if (tem)
-           return tem;
-
-         tem = build1 (code, type, expr);
-         TREE_NO_WARNING (tem) = 1;
-         return tem;
+         return fold_build1 (code, type, expr);
        }
 
       /* If TYPE is an enumeral type or a type with a precision less
index 6d9506edb273333706f8c06640f10308846eadf9..e838343e3b7f2a13dfbdadde88255f2a64555083 100644 (file)
@@ -1,3 +1,11 @@
+2012-04-19  Christian Bruel  <christian.bruel@st.com>
+
+       * gcc.dg/pr52283.c: New test.
+
+2012-04-19   Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       * gcc.dg/pr37985.c: New test.
+
 2012-04-19  Richard Guenther  <rguenther@suse.de>
 
        PR rtl-optimization/44688
diff --git a/gcc/testsuite/gcc.dg/pr37985.c b/gcc/testsuite/gcc.dg/pr37985.c
new file mode 100644 (file)
index 0000000..93e640b
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR c37985 */
+/* { dg-do compile } */
+/* { dg-options " -Wall -Wextra " } */
+unsigned char foo(unsigned char a)
+{
+  a >> 2; /* { dg-warning "no effect" } */
+  return a;
+}
diff --git a/gcc/testsuite/gcc.dg/pr52283.c b/gcc/testsuite/gcc.dg/pr52283.c
new file mode 100644 (file)
index 0000000..33785a5
--- /dev/null
@@ -0,0 +1,16 @@
+/* Test for case labels not integer constant expressions but folding
+   to integer constants (used in Linux kernel).  */
+/* { dg-do compile } */
+
+extern unsigned int u;
+
+void
+b (int c)
+{
+  switch (c)
+    {
+    case (int) (2  | ((4 < 8) ? 8 : u)):
+      ;
+    }
+}
+