-foptimize-sibling-calls and passing structs

Artur Skawina skawina@geocities.com
Sat Jun 3 22:00:00 GMT 2000


i was going to try a recent gcc snapshot , but noticed this...

  struct s { int one; int two; int three; } si = {1,2,3};
  int p( struct s *s ) { printf("%d %d %d\n", s->one, s->two, s->three ); }
  int r( struct s s )  { return p( &s ); }
  int main()           { r( si ); }

r() gets compiled to:

  <r>:
	sub    $0xc,%esp
	lea    0x10(%esp,1),%eax
	mov    %eax,0x10(%esp,1)
	add    $0xc,%esp
	jmp    <p>

which does seem to be a bit aggressive...

  $ gcc -O2 test.c -o /tmp/o && /tmp/o 
  -1073743220 2 3
  $ gcc -O2 test.c -fno-optimize-sibling-calls -o /tmp/o && /tmp/o 
  1 2 3
  $ gcc -v
  Reading specs from /pkg/gcc-ss-20000531-232458/lib/gcc-lib/i386-pc-linux-gnu/2.96/specs
  gcc version 2.96 20000530 (experimental)



More information about the Gcc mailing list