optimization/5768: sh codegen leaves stuff on stack

marcus@mc.pp.se marcus@mc.pp.se
Sun Feb 24 00:18:00 GMT 2002


>Number:         5768
>Category:       optimization
>Synopsis:       sh codegen leaves stuff on stack
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 23 19:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Marcus Comstedt
>Release:        3.0.4
>Organization:
>Environment:
System: SunOS continuity 5.8 Generic_108528-10 sun4m sparc SUNW,SPARCstation-10
Architecture: sun4

	
host: sparc-sun-solaris2.8
build: sparc-sun-solaris2.8
target: sh-unknown-elf
configured with: ../configure --target=sh-elf --with-newlib
>Description:
	When using enough optimization options, the SuperH backend
	can produce code that chains to another function without
	removing its own stackframe.

	Needless to say, this causes the program to go haywire.

	Well, source code should go into the next section, so not
	much more to say here, except that the problem exists in both
	3.0.3 and 3.0.4.

>How-To-Repeat:

	Example program:

	---8<--- foo.c ---8<---

	int x[2];

	void foo()
	{
	  int i;
	  for(i = 0; i<2; i++ )
	    if(x[i]) {
	      bar();
	      return;
	    }
	}
 
	---8<---

	Compile with

	sh-elf-gcc -S -O2 -fomit-frame-pointer -funroll-loops foo.c -o foo.s

	and this is the result:

	---8<--- foo.s ---8<---

		.file	"foo.c"
		.text
		.align 2
		.global	_foo
		.type	_foo,@function
	_foo:
		mov.l	.L17,r1
		mov.l	@r1+,r2
		sts.l	pr,@-r15
		tst	r2,r2
		mov.l	.L18,r3
		bf	.L15
		mov.l	@r1,r2
		tst	r2,r2
		bf	.L16
		lds.l	@r15+,pr
		rts	
		nop
		.align 2
	.L15:
		jmp	@r3
		nop
		.align 2
	.L16:
		jmp	@r3
		nop
	.L19:
		.align 2
	.L17:
		.long	_x
	.L18:
		.long	_bar
	.Lfe1:
		.size	_foo,.Lfe1-_foo
		.comm	_x,8,4
		.ident	"GCC: (GNU) 3.0.4"

	---8<---

	The code at .L15 and .L16 is obviously faulty, as it never
	removes the saved value of pr from the stack.

>Fix:
	Compile with less optimization.  :-6
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list