Code generation bug with -fomit-frame-pointer

James Bursa bursa at users.sourceforge.net
Tue Dec 16 12:00:27 PST 2003


I think I have tracked down a code generation bug with the 
-fomit-frame-pointer option. This is with CVS HEAD gccsdk.

Compiling the function

int test(int x)
{
        printf("x = %i\n", x);
        return x;
}

with no optimization results in:

	mov	__ip, __sp
	stmfd	__sp!, {__v6, __fp, __ip, __lr, __pc}
	sub	__fp, __ip, #4
	cmp	__sp, __sl
	bllt	|__rt_stkovf_split_small|
	sub	__sp, __sp, #4
	mov	__v6, __sp
	str	__a1, [__v6, #0]
	ldr	__a1, |L..2|
	ldr	__a2, [__v6, #0]
	bl	|printf|
	ldr	__a4, [__v6, #0]
	mov	__a1, __a4
	ldmea	__fp, {__v6, __fp, __sp, __pc}

and with -fomit-frame-pointer:

	mov	__ip, __sp
	stmfd	__sp!, {__fp, __ip, __lr, __pc}
	sub	__fp, __ip, #4
	cmp	__sp, __sl
	bllt	|__rt_stkovf_split_small|
	sub	__sp, __sp, #4
	mov	__v6, __sp                        ***
	str	__a1, [__sp, #0]
	ldr	__a1, |L..2|
	ldr	__a2, [__sp, #0]
	bl	|printf|
	ldr	__a4, [__sp, #0]
	mov	__a1, __a4
	ldmea	__fp, {__fp, __sp, __pc}

v6 is no longer stacked in the second version, but is still changed at *** 
above, corrupting it for the caller.

James





More information about the gcc mailing list