This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Strange stack handling


Hi!
This was posted to gnu.gcc.help by Guillaume PELAT and i extended a bit further:

void function4()
{
 char buffer[4];
}

void function5()
{
 char buffer[5];
}

void function8()
{
 char buffer[8];
}

This is snapshot 20010108:

gcc -S bug.c results in

	.file	"h.c"
	.version	"01.01"
gcc2_compiled.:
	.text
	.align 16
.globl function4
	.type	function4,@function
function4:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$4, %esp                     <=====
	movl	%ebp, %esp
	popl	%ebp
	ret
.Lfe1:
	.size	function4,.Lfe1-function4
	.align 16
.globl function5
	.type	function5,@function
function5:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp                    <=====
	movl	%ebp, %esp
	popl	%ebp
	ret
.Lfe2:
	.size	function5,.Lfe2-function5
	.align 16
.globl function8
	.type	function8,@function
function8:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp                     <=====
	movl	%ebp, %esp
	popl	%ebp
	ret
.Lfe3:
	.size	function8,.Lfe3-function8
	.ident	"GCC: (GNU) 2.97 20010108 (experimental)"

Looks strange ...



But even stranger with optimization:
gcc -O -S bug.c results in
	.file	"h.c"
	.version	"01.01"
gcc2_compiled.:
	.text
	.align 16
.globl function4
	.type	function4,@function
function4:
	pushl	%ebp
	movl	%esp, %ebp
	popl	%ebp
	ret
.Lfe1:
	.size	function4,.Lfe1-function4
	.align 16
.globl function5
	.type	function5,@function
function5:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp                        <=====
	movl	%ebp, %esp
	popl	%ebp
	ret
.Lfe2:
	.size	function5,.Lfe2-function5
	.align 16
.globl function8
	.type	function8,@function
function8:
	pushl	%ebp
	movl	%esp, %ebp
	popl	%ebp
	ret
.Lfe3:
	.size	function8,.Lfe3-function8
	.ident	"GCC: (GNU) 2.97 20010108 (experimental)"

So gcc's ability to optimize away unused vars depends on their size?

(the 2.95.3 prerelease produces subl $24 in all 3 cases and optimizes away only
in function[48] like the snapshot does).

Bye,
Martin.

-- 
The early bird gets the worm. If you want something else for       
breakfast, get up later.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]