On Mon, 26 Jun 2006, Richard Guenther wrote:

> On Mon, 26 Jun 2006, Eric Botcazou wrote:
> 
> > > Reverting your patch makes it go away too.  I'll try and look into it
> > > tomorrow.
> > 
> > tree
> > build_string (int len, const char *str)
> > {
> >   tree s;
> >   size_t length;
> >   
> >   length = len + sizeof (struct tree_string);
> > 
> >   s = ggc_alloc_tree (length);
> > 
> > Breakpoint 5, build_string (len=34,
> >     str=0x1048e58 "No space for profiling buffer(s)\n")
> >     at /home/eric/svn/gcc/gcc/tree.c:1124
> > 1124      length = len + sizeof (struct tree_string);
> > (gdb) next
> > 1131      s = ggc_alloc_tree (length);
> > (gdb) p length
> > $1 = 58
> > (gdb) next
> > 1133      memset (s, 0, sizeof (struct tree_common));
> > (gdb) p s
> > $2 = 0xff3803fc
> > 
> > 's' should be 8-byte aligned because it's a "tree".
> 
> The way it works is that ggc_alloc_stat is asked for 58 bytes, which
> if being a correct C object size, has alignof (object) == 2.  Now, with
> 
> struct tree_string GTY(())
> {
>   struct tree_common common;
>   int length;
>   char str[1];
> };
> 
> it is unfortunate that we compute the allocation size by doing magic
> arithmetic instead of asking for  sizeof (struct 
> tree_string_with_length_FOO)  (maybe one can do this with some VLA 
> type?!).

Note that at present

  length = len + sizeof (struct tree_string);

always allocates too much, because sizeof (struct tree_string) is a
multiple of alignof (struct tree_string) and so has the trailing
char[] array padded to 8 bytes (in your case).  So even
(len + sizeof (struct tree_string)) & ~__alignof__(struct tree_string)
might magically work in every case.

Richard.

--
Richard Guenther <[EMAIL PROTECTED]>
Novell / SUSE Labs

Reply via email to