From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5745 invoked by alias); 6 Jul 2004 09:11:30 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 5717 invoked by uid 48); 6 Jul 2004 09:11:26 -0000 Date: Tue, 06 Jul 2004 09:11:00 -0000 From: "zhangjie at magima dot com dot cn" To: gcc-bugs@gcc.gnu.org Message-ID: <20040706091123.16381.zhangjie@magima.com.cn> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/16381] New: Structure layout bug X-Bugzilla-Reason: CC X-SW-Source: 2004-07/txt/msg00461.txt.bz2 List-Id: GCC incorrectly calculated the structure layout in the following case. #include 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