re PR c/49120 (bogus "value computed is not used" warning (variable-length array...
authorJakub Jelinek <jakub@redhat.com>
Mon, 23 May 2011 18:02:03 +0000 (20:02 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 23 May 2011 18:02:03 +0000 (20:02 +0200)
PR c/49120
* c-decl.c (start_decl): Convert expr to void_type_node.

* gcc.dg/pr49120.c: New test.

From-SVN: r174081

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr49120.c [new file with mode: 0644]

index 97719219e4f23d9e512cce3fd767a401a465e6ab..4c73adb37892e3c29150598332ebd94aaba4f683 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/49120
+       * c-decl.c (start_decl): Convert expr to void_type_node.
+
 2011-05-23  Richard Sandiford  <rdsandiford@googlemail.com>
 
        PR rtl-optimization/48826
index 3843f7710f811be5847ec5b75e2e42649c8214b5..a7cc965f78fd5249f85ab978bdc1fd5294d378bb 100644 (file)
@@ -3942,7 +3942,7 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
     return 0;
 
   if (expr)
-    add_stmt (expr);
+    add_stmt (fold_convert (void_type_node, expr));
 
   if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)))
     warning (OPT_Wmain, "%q+D is usually a function", decl);
index 85137d00056f92bfde49c990c52bf416e4811e33..65a3514b44e6fdb9a74cbf8ce04efcb4443d8c7e 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/49120
+       * gcc.dg/pr49120.c: New test.
+
 2011-05-23  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/47315
diff --git a/gcc/testsuite/gcc.dg/pr49120.c b/gcc/testsuite/gcc.dg/pr49120.c
new file mode 100644 (file)
index 0000000..1a65222
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c/49120 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int
+main ()
+{
+  int a = 1;
+  int c = ({ char b[a + 1]; b[0] = 0; b[0]; });
+  return c;
+}