re PR c/31520 (Latent bug in finish_decl causing an errorous "array subscript is...
authorAndrew Pinski <andrew_pinski@playstation.sony.com>
Sun, 15 Apr 2007 00:59:15 +0000 (00:59 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Sun, 15 Apr 2007 00:59:15 +0000 (17:59 -0700)
2007-04-14  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR c/31520
        * c-del.c (finish_decl): Grab the type of the decl after the call
        to store_init_value.
2007-04-14  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR C/31520
        * testsuite/gcc.dg/gnu89-init-4.c: New testcase.

From-SVN: r123835

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

index 1bd9b3ecd73ea7b028e071170e9fdf23bf706c1e..43eff0c148ddd08ae54c65248cb2b11d29e904dd 100644 (file)
@@ -1,3 +1,9 @@
+2007-04-14  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR c/31520
+        * c-del.c (finish_decl): Grab the type of the decl after the call
+       to store_init_value.
+
 2007-04-14  Steven Bosscher  <steven@gcc.gnu.org>
 
        * common.opt (fforward-propagate): Fix "Optimization" annotation.
index eaef0a506b87ccbdd487614f56725fc6694a6c4f..5839fc2e84e01c7074115007f5f443851b8c41c4 100644 (file)
@@ -3383,7 +3383,7 @@ c_maybe_initialize_eh (void)
 void
 finish_decl (tree decl, tree init, tree asmspec_tree)
 {
-  tree type = TREE_TYPE (decl);
+  tree type;
   int was_incomplete = (DECL_SIZE (decl) == 0);
   const char *asmspec = 0;
 
@@ -3410,6 +3410,8 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
                            || TREE_CODE (decl) == FIELD_DECL))
     objc_check_decl (decl);
 
+  type = TREE_TYPE (decl);
+
   /* Deduce size of array from initialization, if not already known.  */
   if (TREE_CODE (type) == ARRAY_TYPE
       && TYPE_DOMAIN (type) == 0
index 2d2c891a366f411bf8b4e33626053338ad5abbd0..7bec6e81d737c9b7356da32d3d2b47cfad8700c3 100644 (file)
@@ -1,3 +1,8 @@
+2007-04-14  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR C/31520
+       * testsuite/gcc.dg/gnu89-init-4.c: New testcase.
+
 2007-04-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/25874
diff --git a/gcc/testsuite/gcc.dg/gnu89-init-4.c b/gcc/testsuite/gcc.dg/gnu89-init-4.c
new file mode 100644 (file)
index 0000000..4ccfbd1
--- /dev/null
@@ -0,0 +1,12 @@
+/* Test for GNU extensions to compound literals are giving the correct array bounds */
+/* { dg-do run } */
+/* { dg-options "-std=gnu89 -W -Wall -O2" } */
+
+int a[] = (int[4]){1, 1, 2};
+int f(void)
+{
+  int sum = 0; int i;
+  for(i = 0;i<4;i++)
+    sum = a[i];
+  return sum;
+}