public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: target/6899: construction of C++ classes with less than 5 bytes of storage can cause stack misalignment
@ 2002-06-14 14:53 ciceron
  0 siblings, 0 replies; 3+ messages in thread
From: ciceron @ 2002-06-14 14:53 UTC (permalink / raw)
  To: ciceron, gcc-bugs, gcc-prs, nobody, stcarrez, thousel

Synopsis: construction of C++ classes with less than 5 bytes of storage can cause stack misalignment

Responsible-Changed-From-To: unassigned->ciceron
Responsible-Changed-By: ciceron
Responsible-Changed-When: Fri Jun 14 14:46:01 2002
Responsible-Changed-Why:
    Concerns HC11/HC12 port
State-Changed-From-To: open->analyzed
State-Changed-By: ciceron
State-Changed-When: Fri Jun 14 14:46:01 2002
State-Changed-Why:
    Problem understood, working on a fix.
    A workarround is to avoid -Os and use -O2.
    Problem is due to a wrong peephole2 enabled only with -Os.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6899


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

* Re: target/6899: construction of C++ classes with less than 5 bytes of storage can cause stack misalignment
@ 2002-07-22 13:29 ciceron
  0 siblings, 0 replies; 3+ messages in thread
From: ciceron @ 2002-07-22 13:29 UTC (permalink / raw)
  To: ciceron, gcc-bugs, gcc-prs, stcarrez, thousel

Synopsis: construction of C++ classes with less than 5 bytes of storage can cause stack misalignment

State-Changed-From-To: analyzed->closed
State-Changed-By: ciceron
State-Changed-When: Mon Jul 22 13:29:24 2002
State-Changed-Why:
    Fixed by http://gcc.gnu.org/ml/gcc-patches/2002-07/msg00293.html
    (was commited on July 6, on 3_1 and mainline)

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6899


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

* target/6899: construction of C++ classes with less than 5 bytes of storage can cause stack misalignment
@ 2002-06-01 13:56 thousel
  0 siblings, 0 replies; 3+ messages in thread
From: thousel @ 2002-06-01 13:56 UTC (permalink / raw)
  To: gcc-gnats; +Cc: stcarrez


>Number:         6899
>Category:       target
>Synopsis:       construction of C++ classes with less than 5 bytes of storage can cause stack misalignment
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 01 13:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     thousel@usa.net
>Release:        gcc compiler 3.1 m68hc1x-20020517
>Organization:
>Environment:
Cygwin/Win2k
>Description:
Under certain scenarios, it appears that a loop of construction of one class followed by a construction of another class with less than 5 bytes of storage will cause stack misalignment.
>How-To-Repeat:
see comments in attachment
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="test.txt"
Content-Disposition: inline; filename="test.txt"

> m6812-elf-gcc -v
Reading specs from /cygdrive/c/m6812-elf-tools/lib/gcc-lib/m6812-elf/3.1/specs
Configured with: ./configure --target=m6812-elf --program-prefix=m6812-elf- --prefix=/cygdrive/c/m6812-elf-tools --exec-prefix=/cygdrive/c/m6812-elf-tools --enable-languages=c,c++
Thread model: single
gcc version 3.1 m68hc1x-20020517


Suppose you have the following code called test.cpp:

class bar {
public :
    bar(int  index);
};

class foo
{
private:
    unsigned short attr1;
    unsigned short attr2;
    unsigned char attr3;
};

class glerg {
public :
    static void Init();
private :
    static foo* pFoo;
};

void glerg::Init() {
    int i;
    bar* pBar[4];
    for (i = 0; i < 4; i++)
        pBar[i] = new bar(i);
    pFoo = new foo();
}

Compile it with:
> m6812-elf-gcc -m68hc12 -mshort -Os -mauto-incdec -fomit-frame-pointer -fno-rtti -fno-exceptions  -S test.cpp

This will create the following test.s:
;;;-----------------------------------------
;;; Start MC68HC11 gcc assembly output
;;; gcc compiler 3.1 m68hc1x-20020517
;;; Command:	/cygdrive/c/m6812-elf-tools/lib/gcc-lib/m6812-elf/3.1/cc1plus.exe -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -Dmc68hc1x -D__mc68hc1x__ -D__mc68hc1x -D__OPTIMIZE_SIZE__ -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -D__HAVE_SHORT_INT__ -D__INT__=16 -D__INT_MAX__=32767 -Dmc6812 -DMC6812 -Dmc68hc12 test.cpp -D__GNUG__=3 -D__DEPRECATED -D__GXX_ABI_VERSION=100 -quiet -dumpbase test.cpp -m68hc12 -mshort -mauto-incdec -Os -fomit-frame-pointer -fno-rtti -fno-exceptions -o test.s
;;; Compiled:	Sat Jun  1 15:42:11 2002
;;; (META)compiled by GNU C version 2.95.3-5 (cygwin special).
;;;-----------------------------------------
	.file	"test.cpp"
	; extern	_Znwt
	; extern	_ZN3barC1Ei
	; extern	_ZN5glerg4pFooE
	; extern	memset
	.sect	.text
	.globl	_ZN5glerg4InitEv
	.type	_ZN5glerg4InitEv,@function
_ZN5glerg4InitEv:
	leas	-16,sp
	clr	9,sp
	clr	8,sp
	sts	14,sp
.L6:
	ldd	#1
	bsr	_Znwt
	std	10,sp
***	movw	8,sp,2,-sp
	ldd	12,sp
	bsr	_ZN3barC1Ei
	ldx	16,sp
	movw	12,sp,2,x+
	stx	16,sp
***	pulx
	ldx	8,sp
	inx
	stx	8,sp
	cpx	#3
	ble	.L6
	ldd	#5
	bsr	_Znwt
	std	12,sp
	movw	#5,2,-sp
	clr	1,-sp
	clr	1,-sp
	ldd	16,sp
	bsr	memset
	ldx	16,sp
	stx	_ZN5glerg4pFooE
	leas	20,sp
	rts
.Lfe1:
	.size	_ZN5glerg4InitEv,.Lfe1-_ZN5glerg4InitEv
	.ident	"GCC: (GNU) 3.1 m68hc1x-20020517"

Note the two lines that begin with "***". The first line autodecrements the
stack by two, and the second uses "pulx" to realign it.

Now we comment out one of the attributes in class foo:

class bar {
public :
    bar(int  index);
};

class foo
{
private:
    unsigned short attr1;
    unsigned short attr2;
//    unsigned char attr3;
};

class glerg {
public :
    static void Init();
private :
    static foo* pFoo;
};

void glerg::Init() {
    int i;
    bar* pBar[4];
    for (i = 0; i < 4; i++)
        pBar[i] = new bar(i);
    pFoo = new foo();
}

Compile it again with:
> m6812-elf-gcc -m68hc12 -mshort -Os -mauto-incdec -fomit-frame-pointer -fno-rtti -fno-exceptions  -S test.cpp

This will create the following test.s:
;;;-----------------------------------------
;;; Start MC68HC11 gcc assembly output
;;; gcc compiler 3.1 m68hc1x-20020517
;;; Command:	/cygdrive/c/m6812-elf-tools/lib/gcc-lib/m6812-elf/3.1/cc1plus.exe -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -Dmc68hc1x -D__mc68hc1x__ -D__mc68hc1x -D__OPTIMIZE_SIZE__ -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -D__HAVE_SHORT_INT__ -D__INT__=16 -D__INT_MAX__=32767 -Dmc6812 -DMC6812 -Dmc68hc12 test.cpp -D__GNUG__=3 -D__DEPRECATED -D__GXX_ABI_VERSION=100 -quiet -dumpbase test.cpp -m68hc12 -mshort -mauto-incdec -Os -fomit-frame-pointer -fno-rtti -fno-exceptions -o test.s
;;; Compiled:	Sat Jun  1 15:44:24 2002
;;; (META)compiled by GNU C version 2.95.3-5 (cygwin special).
;;;-----------------------------------------
	.file	"test.cpp"
	; extern	_Znwt
	; extern	_ZN3barC1Ei
	; extern	_ZN5glerg4pFooE
	.sect	.text
	.globl	_ZN5glerg4InitEv
	.type	_ZN5glerg4InitEv,@function
_ZN5glerg4InitEv:
	leas	-14,sp
	clr	9,sp
	clr	8,sp
	sts	12,sp
.L6:
	ldd	#1
	bsr	_Znwt
	std	10,sp
***	movw	8,sp,2,-sp
	ldd	12,sp
	bsr	_ZN3barC1Ei
	ldx	14,sp
	movw	12,sp,2,x+
	stx	14,sp
???	ldx	8,sp
	inx
	stx	8,sp
	cpx	#3
	ble	.L6
	ldd	#4
	bsr	_Znwt
	tfr	d,x
	clr	3,x
	clr	2,x
	clr	1,x
	clr	0,x
	std	_ZN5glerg4pFooE
	leas	14,sp
	rts
.Lfe1:
	.size	_ZN5glerg4InitEv,.Lfe1-_ZN5glerg4InitEv
	.ident	"GCC: (GNU) 3.1 m68hc1x-20020517"

The generated code is fairly similar, but there is no pulx above the ??? line
this time and the stack therefore becomes misaligned.



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

end of thread, other threads:[~2002-07-22 20:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-14 14:53 target/6899: construction of C++ classes with less than 5 bytes of storage can cause stack misalignment ciceron
  -- strict thread matches above, loose matches on Subject: below --
2002-07-22 13:29 ciceron
2002-06-01 13:56 thousel

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).