re PR c/8032 (GCC >= 3.0 incorrectly initializes static structs in the presence of...
authorEric Botcazou <ebotcazou@libertysurf.fr>
Thu, 9 Jan 2003 09:18:52 +0000 (10:18 +0100)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 9 Jan 2003 09:18:52 +0000 (09:18 +0000)
PR c/8032
* c-typeck.c (process_init_element) [RECORD_TYPE]: For
an empty element, do not advance the pointer to unfilled
fields if there are pending initializers.

From-SVN: r61092

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20030109-1.c [new file with mode: 0644]

index efdc0b46a47672bcb1a43a6c10ca94140f4de2f5..cc6771beeeea76ec64ccb82062c89bf1c5ddb842 100644 (file)
@@ -1,3 +1,10 @@
+2003-01-09  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       PR c/8032
+       * c-typeck.c (process_init_element) [RECORD_TYPE]: For
+       an empty element, do not advance the pointer to unfilled
+       fields if there are pending initializers.
+
 2003-01-09  Christian Cornelssen  <ccorn@cs.tu-berlin.de>
 
        * Makefile.in (ORDINARY_FLAGS_TO_PASS): Also pass DESTDIR.
index 308d0502006ec9434c9b4d12b413eaa22536d3ef..c5b4ecbf9d3e96f837f4cd617510f36647ae4764 100644 (file)
@@ -6609,13 +6609,18 @@ process_init_element (value)
                                bit_position (constructor_fields),
                                DECL_SIZE (constructor_fields));
 
-             constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
-             /* Skip any nameless bit fields.  */
-             while (constructor_unfilled_fields != 0
-                    && DECL_C_BIT_FIELD (constructor_unfilled_fields)
-                    && DECL_NAME (constructor_unfilled_fields) == 0)
-               constructor_unfilled_fields =
-                 TREE_CHAIN (constructor_unfilled_fields);
+             /* If the current field was the first one not yet written out,
+                it isn't now, so update.  */
+             if (constructor_unfilled_fields == constructor_fields)
+               {
+                 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
+                 /* Skip any nameless bit fields.  */
+                 while (constructor_unfilled_fields != 0
+                        && DECL_C_BIT_FIELD (constructor_unfilled_fields)
+                        && DECL_NAME (constructor_unfilled_fields) == 0)
+                   constructor_unfilled_fields =
+                     TREE_CHAIN (constructor_unfilled_fields);
+               }
            }
 
          constructor_fields = TREE_CHAIN (constructor_fields);
index 527d2afbada91a06f4f45332d4b0ad27a77fdc95..2582c719266cbafa6aa7fcfaa76588e51af39cf6 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-09  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       * gcc.c-torture/execute/20030109-1.c: New test.
+
 2003-01-08  Larin Hennessey  <larin@science.oregonstate.edu>
 
        * g++.old-deja/g++.mike/dyncast1.C: Remove reference to AMD A29K
diff --git a/gcc/testsuite/gcc.c-torture/execute/20030109-1.c b/gcc/testsuite/gcc.c-torture/execute/20030109-1.c
new file mode 100644 (file)
index 0000000..1bea931
--- /dev/null
@@ -0,0 +1,20 @@
+/* PR c/8032 */
+/* Verify that an empty initializer inside a partial
+   parent initializer doesn't confuse GCC.  */
+
+struct X
+{
+  int a;
+  int b;
+  int z[];
+};
+
+struct X x = { .b = 40, .z = {} };
+
+int main ()
+{
+  if (x.b != 40)
+    abort ();
+
+  return 0;
+}