When compiling the following code with m68k-elf-gcc and optimization -O, the compiler does not generate code to increment the stack pointer before restoring %fp and returning from the function. This happens in both functions, f1 and f2. I checked with gcc-3.3 and gcc-3.4.3. When using no optimization (no -O), this error doesn't happen. When using -O3, the code in f1 is correct but in f2 is wrong.
Code: struct Value { char type; int val; }; extern struct Value f3(int x); int f2(int a, int b, int c) { return f3(c).val;; } int f1(int nValue) { return f2(0, 0, nValue); } Compilation command line: m68k-elf-gcc -O -Wall -c -m68000 -o test.o test.c Compiler output: <none> Resulting code: 00000000 <f2>: 0: 4e56 fff8 linkw %fp,#-8 4: 2f2e 0010 movel %fp@(16),[EMAIL PROTECTED] 8: 41ee fffa lea %fp@(-6),%a0 c: 4eb9 0000 0000 jsr 0 <f2> 12: 202e fffc movel %fp@(-4),%d0 16: 4e5e unlk %fp 18: 4e75 rts 0000001a <f1>: 1a: 4e56 0000 linkw %fp,#0 1e: 2f2e 0008 movel %fp@(8),[EMAIL PROTECTED] 22: 42a7 clrl [EMAIL PROTECTED] 24: 42a7 clrl [EMAIL PROTECTED] 26: 61d8 bsrs 0 <f2> 28: 4e5e unlk %fp 2a: 4e75 rts Error analysis: Before address 16 in <f2> there is missing a addq #4,%sp and before address 28 in <f1> there is missing a lea %sp@(12),%sp The GCCs I used are cross compilers for m68k-elf compiled on an i686 host. The source was downloaded from an ftp.gnu.org mirror, no patches applied, locally configured and compiled under cygwin. GCC-3.3: $ m68k-elf-gcc -v Reading specs from /tools/H-i686-pc-cygwin/lib/gcc-lib/m68k-elf/3.3/specs Configured with: /src/gcc-3.3/configure --target=m68k-elf --prefix=/tools/H-i686-pc-cygwin --enable-shared --enable-languages=c --with-gnu-as --with-gnu-ld --with-newlib -v Thread model: single gcc version 3.3 GCC-3.4.3: Reading specs from /tools/H-i686-pc-cygwin/lib/gcc/m68k-elf/3.3/specs Configured with: /src/gcc-3.4.3/configure --with-gcc-version-trigger=/src/gcc-3.3/gcc/version.c --host=i686-pc-cygwin --target=m68k-elf --prefix=/tools/H-i686-pc-cygwin --enable-shared --enable-languages=c --with-cpu-68000 --with-gnu-as --with-gnu-ld --with-newlib -v Thread model: single gcc version 3.4.3 -- Summary: Stack pointer error after call to function returning a struct Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: keller at fs-net dot de CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-cygwin GCC host triplet: i686-pc-cygwin GCC target triplet: m68k-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21152