Bug 11446 - [3.4][3.4 regression?] Incompatibilty with alignment of structures between 3.3 and 3.4 CVS
Summary: [3.4][3.4 regression?] Incompatibilty with alignment of structures between 3....
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.0
: P1 critical
Target Milestone: 3.4.0
Assignee: Jason Merrill
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-07-06 18:54 UTC by Andreas Jaeger
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host: i686-linux-gnu
Target: i686-linux-gnu
Build: i686-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-07-06 18:55:40


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Jaeger 2003-07-06 18:54:11 UTC
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. :-(
Comment 1 Andrew Pinski 2003-07-06 19:04:07 UTC
Please do not confirm your own bug.
I can confirm this on the mainline (20030706) and 3.3.1 (20030616), the difference is there.
Comment 2 Dara Hazeghi 2003-07-18 22:32:59 UTC
Which layout is correct though?
Comment 3 janis187 2003-07-31 23:18:33 UTC
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?
Comment 4 GCC Commits 2003-10-20 21:57:49 UTC
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

Comment 5 GCC Commits 2003-10-20 22:02:04 UTC
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

Comment 6 Andrew Pinski 2003-10-20 22:28:43 UTC
Fixed for 3.4.