public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21152] New: Stack pointer error after call to function returning a struct
@ 2005-04-21 15:19 keller at fs-net dot de
  2005-04-21 15:29 ` [Bug target/21152] " pinskia at gcc dot gnu dot org
  2005-04-22 12:16 ` keller at fs-net dot de
  0 siblings, 2 replies; 3+ messages in thread
From: keller at fs-net dot de @ 2005-04-21 15:19 UTC (permalink / raw)
  To: gcc-bugs

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),%sp@-
   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),%sp@-
  22:   42a7            clrl %sp@-
  24:   42a7            clrl %sp@-
  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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/21152] Stack pointer error after call to function returning a struct
  2005-04-21 15:19 [Bug c/21152] New: Stack pointer error after call to function returning a struct keller at fs-net dot de
@ 2005-04-21 15:29 ` pinskia at gcc dot gnu dot org
  2005-04-22 12:16 ` keller at fs-net dot de
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-21 15:29 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/21152] Stack pointer error after call to function returning a struct
  2005-04-21 15:19 [Bug c/21152] New: Stack pointer error after call to function returning a struct keller at fs-net dot de
  2005-04-21 15:29 ` [Bug target/21152] " pinskia at gcc dot gnu dot org
@ 2005-04-22 12:16 ` keller at fs-net dot de
  1 sibling, 0 replies; 3+ messages in thread
From: keller at fs-net dot de @ 2005-04-22 12:16 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-04-22 12:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-21 15:19 [Bug c/21152] New: Stack pointer error after call to function returning a struct keller at fs-net dot de
2005-04-21 15:29 ` [Bug target/21152] " pinskia at gcc dot gnu dot org
2005-04-22 12:16 ` keller at fs-net dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).