[4.5 regression] C++ ignores some aligned attributes (Re: [PATCH] fix arm neon ICE by widening tree_type's precision field)

Ulrich Weigand uweigand@de.ibm.com
Wed Jul 28 19:01:00 GMT 2010


Nathan Froyd wrote:

> 2009-06-09  Nathan Froyd  <froydnj@codesourcery.com>
> 
> 	* tree.h (tree_base): Add packed_flag and user_align fields.
> 	Decrease size of spare field.
> 	(TYPE_USER_ALIGN): Use user_align from tree_base.
> 	(DECL_USER_ALIGN): Likewise.

It seems this broke attribute ((aligned)) handling for certain
cases in C++, which causes crashes in the Mozilla JavaScript
interpreter under some circumstances.

I've opened PR c++/45112 for this problem.  The bug occurs with
code like the following:

struct JSString
{
  unsigned char mLength;
  static JSString unitStringTable[];
};

JSString JSString::unitStringTable[] __attribute__ ((aligned (8))) = { 1 };

(extracted and simplified from Mozilla), where the aligned attribute
seems to be simply ignored from 4.5 on.

The C++ front-end sees two DECLs here, one for the declaration (with
DECL_USER_ALIGN cleared) and one for the definition (with DECL_USER_ALIGN
set).  These are supposed to be merged by cp-decl.c:duplicate_decls.

Before this patch, this would happen inside the following memcpy:

      memcpy ((char *) olddecl + sizeof (struct tree_common),
              (char *) newdecl + sizeof (struct tree_common),
              sizeof (struct tree_decl_common) - sizeof (struct tree_common));

which copied everything in tree_decl_common, *except* what is
in tree_common.

Now, the patch unfortunately moves the user_align (and packed_flag)
fields out of the area copied by this memcpy, and into tree_common.

It seems this means it now ought to be handled manually, but this
code is missing ...

I'll try to come up with a fix.  Any thoughts from C++ folks?

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com



More information about the Gcc-patches mailing list