public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/28862]  New: attribute ((aligned)) ignored on vector variables
@ 2006-08-26 22:22 uweigand at gcc dot gnu dot org
  2006-08-26 22:29 ` [Bug middle-end/28862] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: uweigand at gcc dot gnu dot org @ 2006-08-26 22:22 UTC (permalink / raw)
  To: gcc-bugs

The following test case

__attribute__ ((vector_size (16))) unsigned int foo[128/16]
__attribute__((aligned (128)));

[ and analagously

vector unsigned int foo[128/16] __attribute__((aligned (128)));

on ppc (where "vector" is defined to __attribute__((altivec(vector__)))
or spu (where "vector" is defined to __attribute__((spu_vector))) ]

compiles to

        .comm   foo,128,16

Note that the user-specified alignment is ignored, and the default
alignment of 16 for this vector type is used instead.

The reason appears to be a problem in decl_attributes (attribs.c).
For this declaration, first the "aligned" attribute is processed,
and sets DECL_ALIGN to 128 bytes, as well as the DECL_USER_ALIGN
flag.  However, subsequently the "vector_size" attribute is
processed, and this this is marked as "type_required", the following
piece of code in decl_attributes:

      /* Layout the decl in case anything changed.  */
      if (spec->type_required && DECL_P (*node)
          && (TREE_CODE (*node) == VAR_DECL
              || TREE_CODE (*node) == PARM_DECL
              || TREE_CODE (*node) == RESULT_DECL))
        relayout_decl (*node);

thinks it needs to recompute the decl properties.  In particular,

void
relayout_decl (tree decl)
{
  DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
  DECL_MODE (decl) = VOIDmode;
  DECL_ALIGN (decl) = 0;
  SET_DECL_RTL (decl, 0);

  layout_decl (decl, 0);
}

relayout_decl resets DECL_ALIGN without consideration of the
DECL_USER_ALIGN flag, and layout_decl then fills back in the
default alignment for the vector type.

The problem does not occur in 3.4, since decl_attributes there
works like this:

      /* Layout the decl in case anything changed.  */
      if (spec->type_required && DECL_P (*node)
          && (TREE_CODE (*node) == VAR_DECL
              || TREE_CODE (*node) == PARM_DECL
              || TREE_CODE (*node) == RESULT_DECL))
        {
          /* Force a recalculation of mode and size.  */
          DECL_MODE (*node) = VOIDmode;
          DECL_SIZE (*node) = 0;
          if (!DECL_USER_ALIGN (*node))
            DECL_ALIGN (*node) = 0;

          layout_decl (*node, 0);
        }

and specifically keeps user-requested alignments.


Now, I'm not quite sure what the correct fix for 4.0 and mainline is.
Should be not call relayout_decl (as in 3.4)?  Or should we add the
DECL_USER_ALIGN check to relayout_decl (what about other callers of
this function)?

Richard, it appears you added both the DECL_USER_ALIGN check in
3.4, and the relayout_decl call in 4.0, see PR 18282.  Any opinion?


-- 
           Summary: attribute ((aligned)) ignored on vector variables
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: uweigand at gcc dot gnu dot org


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


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

end of thread, other threads:[~2006-10-09  0:31 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-26 22:22 [Bug c/28862] New: attribute ((aligned)) ignored on vector variables uweigand at gcc dot gnu dot org
2006-08-26 22:29 ` [Bug middle-end/28862] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-09-01  7:10 ` thomas at reactsoft dot com
2006-09-01  8:05 ` thomas at reactsoft dot com
2006-09-01 22:06 ` mmitchel at gcc dot gnu dot org
2006-09-05  4:52 ` pinskia at gcc dot gnu dot org
2006-09-05  7:11 ` thomas at reactsoft dot com
2006-09-05 12:41 ` uweigand at gcc dot gnu dot org
2006-09-05 12:47 ` uweigand at gcc dot gnu dot org
2006-09-06  6:36 ` pinskia at gcc dot gnu dot org
2006-09-06  6:46 ` thomas at reactsoft dot com
2006-09-07  3:30 ` patchapp at dberlin dot org
2006-09-07 15:37 ` [Bug middle-end/28862] [4.0/4.1 " pinskia at gcc dot gnu dot org
2006-09-07 15:37 ` [Bug middle-end/28862] [4.0/4.1/4.2 " pinskia at gcc dot gnu dot org
2006-10-04  7:01 ` [Bug middle-end/28862] [4.0/4.1 " pinskia at gcc dot gnu dot org
2006-10-04  7:02 ` [Bug middle-end/28862] [4.0 " pinskia at gcc dot gnu dot org
2006-10-09  0:30 ` pinskia at gcc dot gnu dot org
2006-10-09  0:31 ` pinskia at gcc dot gnu dot org

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