-fomit-frame-pointer interaction with alloca - egcs-1.0.1
John Hughes
john@AtlanTech.COM
Thu Feb 5 10:17:00 GMT 1998
The "-fomit-frame-pointer" option interacts poorly with alloca.
If a function contains a call to alloca then -fomit-frame-pointer seems to
get turned off.
This is a pity.
What's worse is that some parts of egcs don't seem to know and carry on as
if -fomit-frame pointer was still in effect, generating unnecessary stack
pointer manipulations.
For example, the following test program:
int test (int p) {
printf ("who\n");
{
char *s = alloca (p);
printf ("boo\n");
}
printf ("foo\n");
return 1;
}
Generates code like this:
.file "test.c" .file "test.c"
.version "01.01" .version "01.01"
/ GNU C version egcs-2.90.23 980102 ( / GNU C version egcs-2.90.23 980102 (
/ options passed: -O -fomit-frame-po | / options passed: -O
/ options enabled: -fdefer-pop -fomi | / options enabled: -fdefer-pop -fthr
/ -fpeephole -ffunction-cse -finline | / -finline -fkeep-static-consts -fpcc
/ -fpcc-struct-return -fcommon -fverb | / -fgnu-linker -falias-check -fargume
/ -fargument-alias -m80387 -mhard-flo | / -mno-soft-float -mieee-fp -mfp-ret-
/ -mfp-ret-in-387 -mschedule-prologue | / -march=pentium
gcc2_compiled.: gcc2_compiled.:
.section .rodata .section .rodata
.LC0: .LC0:
.string "who\n" .string "who\n"
.LC1: .LC1:
.string "boo\n" .string "boo\n"
.LC2: .LC2:
.string "foo\n" .string "foo\n"
.text .text
.align 4 .align 4
.globl test .globl test
.type test,@function .type test,@function
test: test:
pushl %ebp pushl %ebp
movl %esp,%ebp movl %esp,%ebp
pushl %ebx pushl %ebx
movl 8(%ebp),%ebx movl 8(%ebp),%ebx
pushl $.LC0 pushl $.LC0
call printf call printf
addl $3,%ebx addl $3,%ebx
andl $-4,%ebx andl $-4,%ebx
addl $4,%esp addl $4,%esp
subl %ebx,%esp subl %ebx,%esp
pushl $.LC1 pushl $.LC1
call printf call printf
pushl $.LC2 pushl $.LC2
call printf call printf
movl $1,%eax movl $1,%eax
addl $8,%esp <
movl -4(%ebp),%ebx movl -4(%ebp),%ebx
leave leave
ret ret
.Lfe1: .Lfe1:
.size test,.Lfe1-test .size test,.Lfe1-test
.ident "GCC: (GNU) egcs-2.90 .ident "GCC: (GNU) egcs-2.90
Note the unnecessary "addl $8,%esp" in the code compiled with
"-fomit-frame-pointer".
(gcc 2.7.2 shows the same problem).
--
John Hughes <john@AtlanTech.COM>,
Atlantic Technologies Inc. Tel: +33-1-43204546
24 rue Montbrun, Fax: +33-1-43204579
75014 PARIS.
More information about the Gcc-bugs
mailing list