[PATCH] Fix alignment bug
Eric Botcazou
ebotcazou@act-europe.fr
Sat Feb 28 23:55:00 GMT 2004
Hi,
This patch fixes one of the alignment issues in the Ada compiler, a
regression introduced by
2002-05-06 Richard Henderson <rth@redhat.com>
PR c++/6212
* expr.c (highest_pow2_factor_for_type): New.
(expand_assignment): Use it.
which authoritatively augments the alignment of an object based on its type.
Unfortunately this is wrong for packed fields in aggregates, as Richard
correctly suggested in
http://gcc.gnu.org/ml/gcc/2002-05/msg00514.html
The problem shows up only in corner cases for C-type languages, but is more
common in Ada because of the semantics of packed aggregates.
The following (admittedly convoluted) C testcase
void foo(int n)
{
struct S {
int i[n];
unsigned int b:1;
int i2;
} __attribute__ ((packed)) __attribute__ ((aligned (4)));
struct S s;
s.i2 = 0;
}
gives an unaligned memory access for 's.i2 = 0' on SPARC, a regression from
GCC 2.95.3 present on all active branches.
The proposed fix is to use DECL_ALIGN instead of TYPE_ALIGN for components of
aggregates, so that the packed-ness is correctly taken into account.
Bootstrapped/regtested on i586-redhat-linux, sparc-sun-solaris2.8 and
sparc64-sun-solaris2.9 (3.4 branch). OK for mainline and 3.4 branch?
2004-02-28 Eric Botcazou <ebotcazou@act-europe.fr>
* expr.c (highest_pow2_factor_for_type): Rename into
highest_pow2_factor_for_target. Use DECL_ALIGN instead of
TYPE_ALIGN when the target is a COMPONENT_REF.
(expand_assignment): Ajust call to highest_pow2_factor_for_type.
2004-02-28 Eric Botcazou <ebotcazou@act-europe.fr>
* gcc.c-torture/execute/20040228-1.c: New test.
--
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20040228-1.c
Type: text/x-csrc
Size: 282 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20040228/dd2c5686/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: expr-2b.diff
Type: text/x-diff
Size: 2673 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20040228/dd2c5686/attachment-0001.bin>
More information about the Gcc-patches
mailing list