crowl@cs.rochester.edu (Lawrence Crowl) (03/18/89)
Gcc 1.34 incorrectly defers popping function parameters that are computed by
value returning blocks. Compiling with the -fno-defer-pop option is a
suitable work-around. Below is a program exhibiting the problem.
int f( a, b )
int a ;
int b ;
{
return a * b ;
}
void main( )
{
int a = 2 ;
int b = 3 ;
int c = 5 ;
int d ;
int e = f( ({ d = f( a, b ) ; d+= 1 ; }), c ) ;
printf( "a==%d b==%d c==%d d==%d e==%d\n", a, b, c, d, e ) ;
}
In summary, the compiler generates:
push c
push b
push a
call f
copy result to d
increment d
push d
call f
However, this leaves parameters b and a to the first call to f INBETWEEN
parameters c and d to to second call to f.
The command "gcc -v -S defer.c" yields:
gcc version 1.34
/usr/su/lib/gcc-cpp -v -undef -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 defer.c /tmp/cca10231.cpp
GNU CPP version 1.34
/usr/su/lib/gcc-cc1 /tmp/cca10231.cpp -quiet -dumpbase defer.c -version -o defer.s
GNU C version 1.34 (68k, MIT syntax) compiled by GNU C version 1.34.
and the assembly code:
#NO_APP
gcc_compiled.:
.text
.even
.globl _f
_f:
link a6,#0
movel a6@(8),d0
mulsl a6@(12),d0
movel d0,d0
jra L1
L1:
unlk a6
rts
LC0:
.ascii "a==%d b==%d c==%d d==%d e==%d\12\0"
.even
.globl _main
_main:
link a6,#-20
moveq #2,d1
movel d1,a6@(-4)
moveq #3,d1
movel d1,a6@(-8)
moveq #5,d1
movel d1,a6@(-12)
movel a6@(-12),sp@-
movel a6@(-8),sp@-
movel a6@(-4),sp@-
jbsr _f
movel d0,d0
movel d0,d0
movel d0,a6@(-16)
movel d0,d0
addql #1,d0
movel d0,d0
movel d0,a6@(-16)
movel d0,sp@-
jbsr _f
movel d0,a6@(-20)
movel a6@(-20),sp@-
movel a6@(-16),sp@-
movel a6@(-12),sp@-
movel a6@(-8),sp@-
movel a6@(-4),sp@-
pea LC0
jbsr _printf
L2:
unlk a6
rts
--
Lawrence Crowl 716-275-9499 University of Rochester
crowl@cs.rochester.edu Computer Science Department
...!{allegra,decvax,rutgers}!rochester!crowl Rochester, New York, 14627