This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16381] New: Structure layout bug
- From: "zhangjie at magima dot com dot cn" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jul 2004 09:11:26 -0000
- Subject: [Bug c++/16381] New: Structure layout bug
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
GCC incorrectly calculated the structure layout in the following case.
#include <stdio.h>
typedef int __m128 __attribute__ ((__mode__(__V4SF__)));
struct Quad
{
Quad() { }
float x __attribute__((aligned(16)));
float y;
float z;
float w;
};
struct Base1
{
Quad q;
int i;
};
struct Derived1 : public Base1
{
int i2;
};
struct Base2
{
__m128 m;
int i;
};
struct Derived2 : public Base2
{
int i2;
};
#define offset(C,M) (int((&((C*)(16))->M))-16)
int main()
{
printf("__m128 size %i, align %i\n", sizeof(__m128), __alignof__(__m128));
printf("Quad size %i, align %i\n", sizeof(Quad), __alignof__(Quad));
printf("Base1 %i Derived1 %i Offset %i\n", sizeof(Base1), sizeof(Derived1),
offset(Derived1, i2) );
printf("Base2 %i Derived2 %i Offset %i\n", sizeof(Base2), sizeof(Derived2),
offset(Derived2, i2) );
return 0;
}
The results on cygwin:
g++ (GCC) 3.3.1 (cygming special)
__m128 size 16, align 16
Quad size 16, align 16
Base1 24 Derived1 24 Offset 20
Base2 24 Derived2 24 Offset 20
g++ (GCC) 3.5.0 20040613 (experimental)
__m128 size 16, align 16
Quad size 16, align 16
Base1 32 Derived1 32 Offset 20
Base2 24 Derived2 32 Offset 24
Neither looks correct.
This test case was given in http://gcc.gnu.org/ml/gcc/2004-06/msg01490.html.
Discussion of this bug began from this mail
http://gcc.gnu.org/ml/gcc/2004-06/msg00622.html.
--
Summary: Structure layout bug
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: zhangjie at magima dot com dot cn
CC: gcc-bugs at gcc dot gnu dot org,nathan at codesourcery
dot com,stephen dot kennedy at havok dot com
GCC host triplet: i686-pc-cygwin
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16381