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]

[patch] varasm: array_size_for_constructor vs STRING_CST



This handles this case:

	struct {char a; char b[];} x = { 'x', "x" };

Not sure what to do about the comment around line 4731, though:
      /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
	 but we cannot do this until the deprecated support for
	 initializing zero-length array members is removed.  */

2001-09-21  DJ Delorie  <dj@redhat.com>

	* varasm.c (array_size_for_constructor): Handle STRING_CST
	also.

Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.207
diff -p -3 -r1.207 varasm.c
*** varasm.c	2001/09/13 14:37:12	1.207
--- varasm.c	2001/09/21 21:06:20
*************** array_size_for_constructor (val)
*** 4572,4577 ****
--- 4572,4584 ----
  {
    tree max_index, i;
  
+   if (TREE_CODE (val) == STRING_CST)
+     {
+       HOST_WIDE_INT len = TREE_STRING_LENGTH(val);
+       HOST_WIDE_INT esz = int_size_in_bytes (TREE_TYPE (TREE_TYPE (val)));
+       HOST_WIDE_INT tsz = len * esz;
+       return tsz;
+     }
    max_index = NULL_TREE;
    for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
      {


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