public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/43798]  New: attribute((aligned(x))) not honored for array element types?
@ 2010-04-19 12:59 rguenth at gcc dot gnu dot org
  2010-04-19 13:05 ` [Bug c/43798] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-19 12:59 UTC (permalink / raw)
  To: gcc-bugs

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.


-- 
           Summary: attribute((aligned(x))) not honored for array element
                    types?
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code, documentation
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43798


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/43798] attribute((aligned(x))) not honored for array element types?
  2010-04-19 12:59 [Bug c/43798] New: attribute((aligned(x))) not honored for array element types? rguenth at gcc dot gnu dot org
@ 2010-04-19 13:05 ` rguenth at gcc dot gnu dot org
  2010-04-19 13:28 ` schwab at linux-m68k dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-19 13:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2010-04-19 13:05 -------
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.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jsm28 at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43798


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/43798] attribute((aligned(x))) not honored for array element types?
  2010-04-19 12:59 [Bug c/43798] New: attribute((aligned(x))) not honored for array element types? rguenth at gcc dot gnu dot org
  2010-04-19 13:05 ` [Bug c/43798] " rguenth at gcc dot gnu dot org
@ 2010-04-19 13:28 ` schwab at linux-m68k dot org
  2010-04-19 13:44 ` jakub at gcc dot gnu dot org
  2010-04-19 13:57 ` rguenther at suse dot de
  3 siblings, 0 replies; 5+ messages in thread
From: schwab at linux-m68k dot org @ 2010-04-19 13:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from schwab at linux-m68k dot org  2010-04-19 13:28 -------
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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43798


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/43798] attribute((aligned(x))) not honored for array element types?
  2010-04-19 12:59 [Bug c/43798] New: attribute((aligned(x))) not honored for array element types? rguenth at gcc dot gnu dot org
  2010-04-19 13:05 ` [Bug c/43798] " rguenth at gcc dot gnu dot org
  2010-04-19 13:28 ` schwab at linux-m68k dot org
@ 2010-04-19 13:44 ` jakub at gcc dot gnu dot org
  2010-04-19 13:57 ` rguenther at suse dot de
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-04-19 13:44 UTC (permalink / raw)
  To: gcc-bugs



------- 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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43798


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/43798] attribute((aligned(x))) not honored for array element types?
  2010-04-19 12:59 [Bug c/43798] New: attribute((aligned(x))) not honored for array element types? rguenth at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-04-19 13:44 ` jakub at gcc dot gnu dot org
@ 2010-04-19 13:57 ` rguenther at suse dot de
  3 siblings, 0 replies; 5+ messages in thread
From: rguenther at suse dot de @ 2010-04-19 13:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenther at suse dot de  2010-04-19 13:57 -------
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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43798


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-04-19 13:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-19 12:59 [Bug c/43798] New: attribute((aligned(x))) not honored for array element types? rguenth at gcc dot gnu dot org
2010-04-19 13:05 ` [Bug c/43798] " rguenth at gcc dot gnu dot org
2010-04-19 13:28 ` schwab at linux-m68k dot org
2010-04-19 13:44 ` jakub at gcc dot gnu dot org
2010-04-19 13:57 ` rguenther at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).