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] [4.5 regression] C++ ignores some aligned attributes


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

It seems this is not the first time this happened, given this comment:

  /* Init priority used to be merged from newdecl to olddecl by the memcpy,
     so keep this behavior.  */
  if (TREE_CODE (newdecl) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (newdecl))
    {
      SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
      DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    }

I've now tried adding similar merges of DECL_USER_ALIGN and DECL_PACKED
at this location, and this does indeed appear to fix the problem for me.

Tested on s390x-ibm-linux with no regressions, fixes the new test.

Does this look correct? If so, OK for mainline and 4.5?

Bye,
Ulrich


ChangeLog:

gcc/
	PR c++/45112
	* cp/decl.c (duplicate_decls): Merge DECL_USER_ALIGN and DECL_PACKED.

gcc/testsuite/
	PR c++/45112
	* testsuite/g++.dg/pr45112.C: New test.


Index: gcc/cp/decl.c
===================================================================
*** gcc/cp/decl.c	(revision 162649)
--- gcc/cp/decl.c	(working copy)
*************** duplicate_decls (tree newdecl, tree oldd
*** 2113,2118 ****
--- 2113,2122 ----
        SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
        DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
      }
+   /* Likewise for DECL_USER_ALIGN and DECL_PACKED.  */
+   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
+   if (TREE_CODE (newdecl) == FIELD_DECL)
+     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
  
    /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
       with that from NEWDECL below.  */
Index: gcc/testsuite/g++.dg/pr45112.C
===================================================================
*** gcc/testsuite/g++.dg/pr45112.C	(revision 0)
--- gcc/testsuite/g++.dg/pr45112.C	(revision 0)
***************
*** 0 ****
--- 1,12 ----
+ /* { dg-do compile } */
+ 
+ struct JSString
+ {
+   unsigned char mLength;
+   static JSString unitStringTable[];
+ };
+ 
+ JSString JSString::unitStringTable[] __attribute__ ((aligned (8))) = { 1 };
+ 
+ int bug [__alignof__ (JSString::unitStringTable) >= 8 ? 1 : -1];
+ 

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


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