Hello,

Is it OK to push the cleaning of TREE_NO_WARNING to fix the constant expressions errors discrepancies, as discussed in bugzilla #52283, now that the trunk is open ?


Many thanks,



2012-03-29   Manuel López-Ibáñez  <m...@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.

2010-03-29  Christian Bruel  <christian.br...@st.com>

	PR c/52283
	* gcc.dg/case-const-1.c: Test constant expression.
	* gcc.dg/case-const-2.c: Likewise.
	* gcc.dg/case-const-3.c: Likewise.

2012-03-29   Manuel López-Ibáñez  <m...@gcc.gnu.org>

	* gcc/testsuite/gcc.dg/pr37985.c: New test.

Index: gcc/testsuite/gcc.dg/pr37985.c
===================================================================
--- gcc/testsuite/gcc.dg/pr37985.c	(revision 0)
+++ gcc/testsuite/gcc.dg/pr37985.c	(revision 0)
@@ -0,0 +1,8 @@
+/* PR c/37985 */
+/* { dg-do compile } */
+/* { dg-options " -Wall -Wextra " } */
+unsigned char foo(unsigned char a)
+{
+  a >> 2; /* { dg-warning "no effect" } */
+  return a;
+}
Index: gcc/testsuite/gcc.dg/case-const-1.c
===================================================================
--- gcc/testsuite/gcc.dg/case-const-1.c	(revision 186082)
+++ gcc/testsuite/gcc.dg/case-const-1.c	(working copy)
@@ -1,9 +1,11 @@
 /* Test for case labels not integer constant expressions but folding
-   to integer constants (used in Linux kernel, PR 39613).  */
+   to integer constants (used in Linux kernel, PR 39613, 52283).  */
 /* { dg-do compile } */
 /* { dg-options "" } */
 
 extern int i;
+extern unsigned int u;
+
 void
 f (int c)
 {
@@ -13,3 +15,13 @@
       ;
     }
 }
+
+void
+b (int c)
+{
+  switch (c)
+    {
+    case (int) (2  | ((4 < 8) ? 8 : u)):
+      ;
+    }
+}
Index: gcc/testsuite/gcc.dg/case-const-2.c
===================================================================
--- gcc/testsuite/gcc.dg/case-const-2.c	(revision 186082)
+++ gcc/testsuite/gcc.dg/case-const-2.c	(working copy)
@@ -1,9 +1,11 @@
 /* Test for case labels not integer constant expressions but folding
-   to integer constants (used in Linux kernel, PR 39613).  */
+   to integer constants (used in Linux kernel, PR 39613, 52283).  */
 /* { dg-do compile } */
 /* { dg-options "-pedantic" } */
 
 extern int i;
+extern unsigned int u;
+
 void
 f (int c)
 {
@@ -13,3 +15,14 @@
       ;
     }
 }
+
+void
+b (int c)
+{
+  switch (c)
+    {
+    case (int) (2  | ((4 < 8) ? 8 : u)): /* { dg-warning "case label is not an integer constant expression" } */
+      ;
+    }
+}
+
Index: gcc/testsuite/gcc.dg/case-const-3.c
===================================================================
--- gcc/testsuite/gcc.dg/case-const-3.c	(revision 186082)
+++ gcc/testsuite/gcc.dg/case-const-3.c	(working copy)
@@ -1,9 +1,11 @@
 /* Test for case labels not integer constant expressions but folding
-   to integer constants (used in Linux kernel, PR 39613).  */
+   to integer constants (used in Linux kernel, PR 39613, 52283, ).  */
 /* { dg-do compile } */
 /* { dg-options "-pedantic-errors" } */
 
 extern int i;
+extern unsigned int u;
+
 void
 f (int c)
 {
@@ -13,3 +15,16 @@
       ;
     }
 }
+
+void
+b (int c)
+{
+  switch (c)
+    {
+    case (int) (2  | ((4 < 8) ? 8 : u)): /* { dg-error "case label is not an integer constant expression" } */
+      ;
+    }
+}
+
+
+
Index: gcc/stmt.c
===================================================================
--- gcc/stmt.c	(revision 186082)
+++ gcc/stmt.c	(working copy)
@@ -1515,6 +1515,7 @@
 
     case SAVE_EXPR:
     case NON_LVALUE_EXPR:
+    case NOP_EXPR:
       exp = TREE_OPERAND (exp, 0);
       goto restart;
 
Index: gcc/convert.c
===================================================================
--- gcc/convert.c	(revision 186082)
+++ gcc/convert.c	(working copy)
@@ -542,7 +542,6 @@
       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,
@@ -560,13 +559,7 @@
 	  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

Reply via email to