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]

[PATCH] Tiny fix to store_constructor


Hi,

GCC 3.2.x has a sanity check:

      if (size > 0)

in store_constructor, just before the infamous clearing optimization:

	{
	  clear_storage (target, GEN_INT (size));
	  cleared = 1;
	}


It has been lifted since GCC 3.3 and this is problematic for arrays derived
from unconstrained arrays in Ada like:

    type My_Array is array
		    (Integer range <>, Integer range <>) of Element;

because int_expr_size may return -1 for them (variable size) so we end up 
with:

   memset (addr, 0, -1);

in the assembly file, which is not nice.


The attached patch restores the sanity check.  Bootstrapped/regtested on 
i586-redhat-linux-gnu (mainline).  OK for mainline?

Mark, do you want it on the 3.4 branch too?


2004-05-27  Olivier Hainque  <hainque@act-europe.fr>

	* expr.c (store_constructor): Restore sanity check on
	the size of the type before clearing.


-- 
Eric Botcazou
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.647
diff -u -p -r1.647 expr.c
--- expr.c	19 May 2004 06:26:21 -0000	1.647
+++ expr.c	27 May 2004 05:49:52 -0000
@@ -4673,8 +4673,9 @@ store_constructor (tree exp, rtx target,
 	 clear the whole structure first.  Don't do this if TARGET is a
 	 register whose mode size isn't equal to SIZE since clear_storage
 	 can't handle this case.  */
-      else if (((list_length (CONSTRUCTOR_ELTS (exp)) != fields_length (type))
-		|| mostly_zeros_p (exp))
+      else if (size > 0
+	       && ((list_length (CONSTRUCTOR_ELTS (exp)) != fields_length (type))
+		   || mostly_zeros_p (exp))
 	       && (GET_CODE (target) != REG
 		   || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
 		       == size)))

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