This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR c/8032


> Just a minor nit, shouldn't you use the C99 initializer syntax here? IIRC
> this GCC specific syntax will be deprecated relatively soon and then we
> have to fixup the testcase again, or?

OK, here's the C99 version with flexible array members and initializers, 
together with a more accurate ChangeLog entry. I verified that it still fails 
with an unpatched GCC.

-- 
Eric Botcazou


2002-11-26  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.


2002-11-26  Eric Botcazou  <ebotcazou@libertysurf.fr>

	* gcc.c-torture/execute/20021126-1.c: New test.


Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.212
diff -u -r1.212 c-typeck.c
--- c-typeck.c	4 Nov 2002 00:22:57 -0000	1.212
+++ c-typeck.c	26 Nov 2002 08:09:33 -0000
@@ -6618,13 +6618,18 @@
 			        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);


/* 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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]