Bug 90567 - typedefs + ailgned attribute confuses gcc
typedefs + ailgned attribute confuses gcc
Status: CLOSED NEXTRELEASE
Product: Red Hat Enterprise Linux 2.1
Classification: Red Hat
Component: gcc (Show other bugs)
2.1
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-05-09 13:52 EDT by Eric Sandeen
Modified: 2007-11-30 17:06 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-10-04 18:35:21 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Eric Sandeen 2003-05-09 13:52:42 EDT
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;
}
Comment 1 Eric Sandeen 2003-05-09 14:11:48 EDT
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)
Comment 2 Vladimir Makarov 2004-10-04 18:35:21 EDT
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.

Comment 3 Eric Sandeen 2004-10-04 21:48:14 EDT
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

Note You need to log in before you can comment on or make changes to this bug.