User account creation filtered due to spam.

Bug 43798 - attribute((aligned(x))) not honored for array element types?
Summary: attribute((aligned(x))) not honored for array element types?
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: documentation, wrong-code
Depends on:
Blocks:
 
Reported: 2010-04-19 12:59 UTC by Richard Biener
Modified: 2010-04-19 13:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2010-04-19 12:59:14 UTC
in libbid we have

typedef __attribute__((aligned(16)))
struct {
    unsigned long long w[3];
} UINT192;

UINT192 bid_Kx192[32];

thus we request 16-byte alignment for UINT192 (whose elements add
up to a size of 24).  Now the array ends up with elements of size 24
and thus the elements are _not_ aligned to a 16-byte boundary, still
the element type is not adjusted to reflect that leading to inconsistencies
when one for example tries to set operand 3 of an ARRAY_REF
(which is specified in units of the alignment of the element).

This causes PR43783.

This is also at least a documentation bug as I can't find anything
that documents the above behavior.
Comment 1 Richard Biener 2010-04-19 13:05:03 UTC
Namely the bid_Kx192 decl looks like

 <var_decl 0x7ffff5af8000 bid_Kx192
    type <array_type 0x7ffff5add7e0
        type <record_type 0x7ffff5add690 UINT192 type_0 BLK
            size <integer_cst 0x7ffff7ef70c8 constant 192>
            unit size <integer_cst 0x7ffff7ef7078 constant 24>
            user align 128 symtab 0 alias set -1 canonical type 0x7ffff5add498 fields <field_decl 0x7ffff7fb34c0 w> context <translation_unit_decl 0x7ffff5afe000 D.1631>
            pointer_to_this <pointer_type 0x7ffff5add888>>
        BLK
        size <integer_cst 0x7ffff7ef7258 constant 6144>
        unit size <integer_cst 0x7ffff7fcfaa0 constant 768>
        user align 128 symtab 0 alias set -1 canonical type 0x7ffff5add9d8
        domain <integer_type 0x7ffff5add738>
        pointer_to_this <pointer_type 0x7ffff5afc000>>
    addressable used public static common BLK file t.c line 6 col 9 size <integer_cst 0x7ffff7ef7258 6144> unit size <integer_cst 0x7ffff7fcfaa0 768>
    align 256 chain <function_decl 0x7ffff5adcb00 main>>

where the TYPE_ALIGN of the element type only applies to the first
array element.  If you look at expr.c:array_ref_element_size then you
can see that there doesn't exist a valid TREE_OPERAND (array-ref, 3)
for indexing the above array as its TYPE_ALIGN_UNIT is bigger than
the aligned-size.

IMHO the C frontend ought to generate a variant type for the element
type that has its alignment adjusted (or it shall follow the users
request and add padding between the elements?).  The current situation
is unfortunate for the middle-end.
Comment 2 Andreas Schwab 2010-04-19 13:28:32 UTC
An array cannot have internal padding, so the padding needs to be added to the element type.
The attempt to define such an array should probably be rejected.
Comment 3 Jakub Jelinek 2010-04-19 13:44:06 UTC
At least with pointers alignment greater than size of the pointed to type (or not divisible by it) is often used to say that the start of the array is aligned some way.
Comment 4 rguenther@suse.de 2010-04-19 13:57:09 UTC
Subject: Re:  attribute((aligned(x))) not honored for array
 element types?

On Mon, 19 Apr 2010, jakub at gcc dot gnu dot org wrote:

> ------- Comment #3 from jakub at gcc dot gnu dot org  2010-04-19 13:44 -------
> At least with pointers alignment greater than size of the pointed to type (or
> not divisible by it) is often used to say that the start of the array is
> aligned some way.

Yes, we correctly copy the (over-)alignment of the element type to
the array type.  But the element type alignment then stays "wrong".

Richard.