public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/16381] New: Structure layout bug
@ 2004-07-06  9:11 zhangjie at magima dot com dot cn
  2004-07-06 15:42 ` [Bug c++/16381] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: zhangjie at magima dot com dot cn @ 2004-07-06  9:11 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-10-28  7:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-06  9:11 [Bug c++/16381] New: Structure layout bug zhangjie at magima dot com dot cn
2004-07-06 15:42 ` [Bug c++/16381] " pinskia at gcc dot gnu dot org
2004-08-16 10:47 ` [Bug c++/16381] [3.3/3.4/3.5 Regression] " giovannibajo at libero dot it
2004-08-17  6:39 ` [Bug c++/16381] [3.3/3.5 " mmitchel at gcc dot gnu dot org
2004-08-17  7:31 ` zhangjie at magima dot com dot cn
2004-08-17  9:53 ` zhangjie at magima dot com dot cn
2004-08-17 10:04 ` zhangjie at magima dot com dot cn
2004-10-28  6:00 ` [Bug c++/16381] [3.3/4.0 " mmitchel at gcc dot gnu dot org
2004-10-28  6:18 ` mmitchel at gcc dot gnu dot org
2004-10-28  7:14 ` dannysmith at users dot sourceforge dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).