On i686-linux-gnu the struct-align-1 testcase fails if I mix objects from GCC 3.3 and GCC 3.4 using current CVS versions, the testsuite reports: FAIL: gcc.dg/compat/struct-align-1 c_compat_x_tst.o-c_compat_y_alt.o execute FAIL: gcc.dg/compat/struct-align-1 c_compat_x_alt.o-c_compat_y_tst.o execute Here's an example compile session: $ /opt/gcc/3.3-devel/bin/gcc -c -DDBG struct-align-1_x.c $ /opt/gcc/3.4-devel/bin/gcc -c -DDBG struct-align-1_y.c $ /opt/gcc/3.4-devel/bin/gcc -c -DDBG struct-align-1_main.c $ /opt/gcc/3.4-devel/bin/gcc -DDBG *.o -o struct-align-1 $ ./struct-align-1 original global variable....... global array....... argument....... function result....... packed attribute for all global variable....... global array....... argument....... function result....... packed attribute for inner global variable....... global array....... argument....... function result....... packed attribute for outer global variable....... global array....... argument....... function result....... maximum useful struct alignment for all global variable....... global array....... argument....... function result....... maximum alignment for outer, packed inner global variable....... global array....... argument....... function result....... maximum alignment for inner, packed outer global variable...F.FF global array..FFFFF argument...F.FF function result...F.FF failed Aborted gromit:~/tmp/align-1:[134]$ The structure that fails is: #define DESC_m_inner_p_outer "maximum alignment for inner, packed outer" struct B1_m_inner_p_outer { char c; double d; } __attribute__ ((aligned)) __attribute__ ((packed)); A diff between struct_align-1_x.s between GCC 3.3 and 3.4 shows: .globl b2_a_max - .align 32 + .align 16 ... .globl b2_m_inner_p_outer + .align 16 .type b2_m_inner_p_outer, @object - .size b2_m_inner_p_outer, 17 + .size b2_m_inner_p_outer, 32 ... .globl ab2_m_inner_p_outer - .align 32 + .align 16 .type ab2_m_inner_p_outer, @object - .size ab2_m_inner_p_outer, 34 + .size ab2_m_inner_p_outer, 64 So, we have different alignment and therefore sizes. :-(
Please do not confirm your own bug. I can confirm this on the mainline (20030706) and 3.3.1 (20030616), the difference is there.
Which layout is correct though?
The sizes and alignments of the structs in PR 11446 changed with this patch: --- gcc/gcc/ChangeLog --- 2003-04-03 Jason Merrill <jason@redhat.com> * stor-layout.c (do_type_align): New fn, split out from... (layout_decl): ...here. Do all alignment calculations for FIELD_DECLs here. (update_alignment_for_field): Not here. (start_record_layout, debug_rli): Remove unpadded_align. * tree.h (struct record_layout_info_s): Remove unpadded_align. * c-decl.c (finish_enum): Don't set DECL_SIZE, DECL_ALIGN or DECL_MODE on the CONST_DECLs. (finish_struct): Don't mess with DECL_ALIGN. --- gcc/gcc/cp/ChangeLog --- 2003-04-03 Jason Merrill <jason@redhat.com> * class.c (build_vtable): Set DECL_ALIGN here. (get_vtable_decl): Not here. (layout_vtable_decl): Or here. (create_vtable_ptr): Or here. (layout_class_type): Or here. (check_bitfield_decl): Don't mess with field alignment. I used the following test on i686-pc-linux-gnu and watched for the size of b2 to become 32: ------------------------------------------------------------------ struct A2_m_inner_p_outer { double d; } __attribute__ ((aligned)); struct B2_m_inner_p_outer { char c; struct A2_m_inner_p_outer a2; } __attribute__ ((packed)); struct B2_m_inner_p_outer b2 = { 1, { 2.0 } }; struct B2_m_inner_p_outer a2[2] = { { 1, { 2.0 } }, { 2, { 3.0 } } }; ------------------------------------------------------------------ Here's the definition of b2 before and after the patch: .globl b2 .data + .align 16 .type b2, @object - .size b2, 17 + .size b2, 32 b2: .byte 1 + .zero 15 .long 0 .long 1073741824 .zero 8 I don't know what the expected sizes and alignments are; Jason, is this change expected?
Subject: Bug 11446 CVSROOT: /cvs/gcc Module name: gcc Changes by: jason@gcc.gnu.org 2003-10-20 21:57:42 Modified files: gcc : tree.c stor-layout.c ChangeLog Log message: PR c/12553 * tree.c (build1) <ADDR_EXPR>: Set TREE_SIDE_EFFECTS appropriately. PR c/11446 * stor-layout.c (layout_decl): Fix alignment handling. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.c.diff?cvsroot=gcc&r1=1.333&r2=1.334 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stor-layout.c.diff?cvsroot=gcc&r1=1.170&r2=1.171 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1492&r2=2.1493
Subject: Bug 11446 CVSROOT: /cvs/gcc Module name: gcc Changes by: jason@gcc.gnu.org 2003-10-20 22:01:59 Added files: gcc/testsuite/gcc.dg: pack-test-5.c Log message: PR c/11446 * stor-layout.c (layout_decl): Fix alignment handling. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pack-test-5.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Fixed for 3.4.