From Bugzilla Helper: User-Agent: Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20030131 Description of problem: When using the aligned attribute on a typedef'd variable, this attribute seems to get lost. Version-Release number of selected component (if applicable): gcc-2.96-113 How reproducible: Always Steps to Reproduce: 1. Compile the test code below 2. Observe incorrect output - 2nd structure member is not 8-byte aligned Actual Results: sizeof my_struct 12 offset of foo in my_struct is 0 offset of bar in my_struct is 4 Expected Results: sizeof my_struct 16 offset of foo in my_struct is 0 offset of bar in my_struct is 8 Additional info: I expect that this is a problem with the GCC in RHAS 2.1 as well, although I do not have a 32-bit box with RHAS to test. the gcc v3 compilers in Red Hat Linux 8.0 and later generate correct code. gcc version 2.95.4 20011002 (Debian prerelease) from debian unstable also generates correct code. This may be related to gcc bug 3580, bugzilla.redhat.com/bugzilla/show_bug.cgi?id=54724 ---------- #include <stdio.h> #include <sys/types.h> #define ALIGN_8BYTE __attribute__((__aligned__(8))) #undef offsetof #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #if 1 /* This way is broken */ typedef int64_t aligned_int64_t ALIGN_8BYTE; typedef struct { int foo; aligned_int64_t bar; } my_struct; #endif #if 0 /* It works fine this way */ typedef struct { int foo; int64_t bar ALIGN_8BYTE; } my_struct; #endif int main(int argc, char **argv) { printf("sizeof my_struct %d\n", sizeof(my_struct)); printf("offset of foo in my_struct is %d\n", offsetof(my_struct, foo)); printf("offset of bar in my_struct is %d\n", offsetof(my_struct, bar)); return 0; }
gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-108.1) in RHAS 2.1 on x86 demonstrates this bug as well. (Sorry, can't set the Version field to 2.1 from here, I guess)
gcc-2.96 is too old. Its release cycle was finished long ago. Therefore I am closing the case. The bug was fixed at least in 3.2 (rhel3). If it is still important, the customer could reopen the case.
If you want to close this one, fine, but bug 109911 shows that this is still a problem in newer gccs as well. I don't think it has ever been formally addressed; rather it seems to be a bug that gets exposed and hidden as the gcc codebase changes. My concern is that the gcc that winds up releasing with RHEL4 may exhibit the problem as well, so I'm trying to keep an eye on FC... Thanks, -Eric