[Bug c/21152] New: Stack pointer error after call to function returning a struct

2005-04-21 Thread keller at fs-net dot de
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:

  


Resulting code:

 :
   0:   4e56 fff8   linkw %fp,#-8
   4:   2f2e 0010   movel %fp@(16),[EMAIL PROTECTED]
   8:   41ee fffa   lea %fp@(-6),%a0
   c:   4eb9    jsr 0 
  12:   202e fffc   movel %fp@(-4),%d0
  16:   4e5eunlk %fp
  18:   4e75rts

001a :
  1a:   4e56    linkw %fp,#0
  1e:   2f2e 0008   movel %fp@(8),[EMAIL PROTECTED]
  22:   42a7clrl [EMAIL PROTECTED]
  24:   42a7clrl [EMAIL PROTECTED]
  26:   61d8bsrs 0 
  28:   4e5eunlk %fp
  2a:   4e75rts


Error analysis:

Before address 16 in  there is missing a

  addq #4,%sp

and before address 28 in  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


[Bug target/21152] Stack pointer error after call to function returning a struct

2005-04-22 Thread keller at fs-net dot de

--- Additional Comments From keller at fs-net dot de  2005-04-22 12:16 
---
Sorry, I made a mistake. I misinterpreted how the 68000 assembler instruction
UNLK works. The stack correction is in fact not required, so the generated code
can be considered correct.

I had an error in my code that I thought was caused by the above inconsistency
(sometimes the stack is corrected before unlinking %fp, sometimes not). But I
could track down the error in my code to some other cause.

So herewith I'd like to withdraw my bug report.

Sorry again for bothering you.


-- 
   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||WORKSFORME


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21152