[PATCH] Fix C array constructor handling

Jakub Jelinek jakub@redhat.com
Thu Oct 25 03:27:00 GMT 2001


Hi!

The testcase below causes gcc to loop forever printing:
...
20011025-1.c:3: initializer element is not constant
20011025-1.c:3: (near initialization for `foo')
20011025-1.c:3: initializer element is not constant
20011025-1.c:3: (near initialization for `foo')
20011025-1.c:3: initializer element is not constant
20011025-1.c:3: (near initialization for `foo')
...
Solved by removing the 3 digest_init calls in output_init_element and move
that call before value == error_mark_node checking (digest_init with INIT ==
error_mark_node will return it too).
Ok to commit?

2001-10-25  Jakub Jelinek  <jakub@redhat.com>

	* c-typeck.c (output_init_element): Call digest_init
	just once, not in each if branch and check its return value for
	error_mark_node.

	* gcc.dg/noncompile/20011025-1.c: New test.

--- gcc/c-typeck.c.jj	Thu Oct 25 11:13:07 2001
+++ gcc/c-typeck.c	Thu Oct 25 12:35:58 2001
@@ -4652,7 +4652,7 @@ digest_init (type, init, require_constan
 
   if (type == error_mark_node
       || init == error_mark_node
-      || TREE_TYPE (init)  == error_mark_node)
+      || TREE_TYPE (init) == error_mark_node)
     return error_mark_node;
 
   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
@@ -6210,6 +6210,8 @@ output_init_element (value, type, field,
 		  || TREE_CHAIN (field)))))
     return;
 
+  value = digest_init (type, value, require_constant_value,
+		       require_constant_elements);
   if (value == error_mark_node)
     {
       constructor_erroneous = 1;
@@ -6226,9 +6228,7 @@ output_init_element (value, type, field,
 	  && tree_int_cst_lt (field, constructor_unfilled_index))
 	set_nonincremental_init ();
 
-      add_pending_init (field,
-			digest_init (type, value, require_constant_value, 
-				     require_constant_elements));
+      add_pending_init (field, value);
       return;
     }
   else if (TREE_CODE (constructor_type) == RECORD_TYPE
@@ -6254,9 +6254,7 @@ output_init_element (value, type, field,
 	    }
 	}
 
-      add_pending_init (field,
-			digest_init (type, value, require_constant_value, 
-				     require_constant_elements));
+      add_pending_init (field, value);
       return;
     }
   else if (TREE_CODE (constructor_type) == UNION_TYPE
@@ -6275,10 +6273,7 @@ output_init_element (value, type, field,
   if (field && TREE_CODE (field) == INTEGER_CST)
     field = copy_node (field);
   constructor_elements
-    = tree_cons (field, digest_init (type, value,
-				     require_constant_value, 
-				     require_constant_elements),
-		 constructor_elements);
+    = tree_cons (field, value, constructor_elements);
 
   /* Advance the variable that indicates sequential elements output.  */
   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
--- gcc/testsuite/gcc.dg/noncompile/20011025-1.c.jj	Thu Oct 25 12:23:52 2001
+++ gcc/testsuite/gcc.dg/noncompile/20011025-1.c	Thu Oct 25 12:27:31 2001
@@ -0,0 +1,5 @@
+double foo [] =
+{ &bar,		/* { dg-error "undeclared|is not constant|near init" } */
+  (void *) 0 };	/* { dg-error "incompatible types|is not constant|near init" } */
+double baz [] =
+{ (void *) 0 };	/* { dg-error "incompatible types|is not constant|near init" } */

	Jakub



More information about the Gcc-patches mailing list