This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/14190] New: __attribute__ ((aligned(8))) inside a union has no effect


An __attribute__ ((aligned(8))), added to a member of a union, should have
the effect that the entire union should be at least 8 bytes aligned. This
is also how it worked in gcc-2.7.2. But in gcc-3.3.1 it doesn't work any more.

Environment:
System: Linux linuix 2.4.21-99-default #1 Wed Sep 24 13:30:51 UTC 2003 i686 athlon i386 GNU/Linux
Architecture: i686

host: i586-suse-linux-gnu
build: i586-suse-linux-gnu
target: i586-suse-linux-gnu
configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --disable-checking --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux

How-To-Repeat:

Look at the definition of struct2 here:
============================= bug.c ===================================
typedef unsigned long uintL;
typedef unsigned long long oint;

typedef struct {
  union {
    struct { uintL addr; uintL type; } both;
    oint one_u;
  } u;
} struct1;

typedef struct {
  union {
    struct { uintL addr; uintL type; } both;
    oint one_u __attribute__ ((aligned(8)));
  } u;
} struct2;

typedef struct {
  union {
    struct { uintL addr; uintL type; } both;
    oint one_u __attribute__ ((aligned(8)));
  } u __attribute__ ((aligned(8)));
} struct3;

int a1 = __alignof (struct1);
int a2 = __alignof (struct2);
int a3 = __alignof (struct3);

int main () { printf ("%d %d %d\n", a1, a2, a3); }
=======================================================================

$ gcc bug.c
$ ./a.out
4 4 8

Expected:

$ ./a.out
4 8 8
------- Additional Comments From bruno at clisp dot org  2004-02-18 12:14 -------
Fix:

A workaround is to use an __attribute__((aligned(8))) also on the union
itself (see struct3 above).

-- 
           Summary: __attribute__ ((aligned(8))) inside a union has no
                    effect
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bruno at clisp dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i586-suse-linux-gnu
  GCC host triplet: i586-suse-linux-gnu
GCC target triplet: i586-suse-linux-gnu


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]