Bug 53040 - nested functions may trash floating point registers
Summary: nested functions may trash floating point registers
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-19 11:10 UTC by Alan Modra
Modified: 2013-02-07 01:39 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-04-19 00:00:00


Attachments
obvious fix (461 bytes, patch)
2012-04-19 15:24 UTC, Alan Modra
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Modra 2012-04-19 11:10:11 UTC
compile with -m32 -Os -fno-inline
void ws_f (void)
{
  char b[10];
  void ns_f (void)
  {
    char a[33];
    __asm __volatile ("#%0 %1" : "=m" (a), "=m" (b) : : "fr28", "fr31");
  }
  ns_f ();
}

results in

ns_f.2345:
        stwu 1,-96(1)
        mflr 0
        stfd 28,64(1)
        stw 0,100(1)
        stfd 31,88(1)
[snip]
        addi 11,1,96
        b _restfpr_28_x

_restfpr_28_x will restore fr29 and fr30 from uninitialised stack.
Comment 1 Alan Modra 2012-04-19 15:24:30 UTC
Created attachment 27191 [details]
obvious fix
Comment 2 Alan Modra 2012-04-20 09:33:23 UTC
Author: amodra
Date: Fri Apr 20 09:33:19 2012
New Revision: 186616

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186616
Log:
	PR target/53040
	* config/rs6000/rs6000.c (rs6000_savres_strategy): When using
	static chain, set REST_INLINE_FPRS too.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000.c
Comment 3 Alan Modra 2013-02-06 02:39:54 UTC
Fixed.  Not a regression so not applying to FSF branches.
Comment 4 Alan Modra 2013-02-06 02:46:24 UTC
Author: amodra
Date: Wed Feb  6 02:46:13 2013
New Revision: 195778

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195778
Log:
	PR target/53040
	* config/rs6000/rs6000.c (rs6000_savres_strategy): When using
	static chain, set REST_INLINE_FPRS too.


Modified:
    branches/ibm/gcc-4_7-branch/gcc/ChangeLog.ibm
    branches/ibm/gcc-4_7-branch/gcc/config/rs6000/rs6000.c
Comment 5 Eric Botcazou 2013-02-06 11:49:59 UTC
Can you reconsider?  If that's an obvious fix for an annoying target problem, then it should be put at least on the 4.7 branch.  There are plenty of precedents for other targets (x86, SPARC, ARM, etc).
Comment 6 Alan Modra 2013-02-06 13:31:45 UTC
This one is hardly an annoying bug.  You need
a) nested functions,
b) using floating point,
c) with an unusual set of callee saved fprs,
d) and -Os.

I found the bug only because I wrote a fairly complete test for prologue/epilogue code.

OTOH, the patch is quite obvious and completely safe..
Comment 7 Eric Botcazou 2013-02-06 16:45:44 UTC
> This one is hardly an annoying bug.  You need
> a) nested functions,
> b) using floating point,
> c) with an unusual set of callee saved fprs,
> d) and -Os.

a) + b) + d) is pretty much standard e.g. for embedded Ada on PowerPC/VxWorks.

> OTOH, the patch is quite obvious and completely safe..

Then I think it's a good candidate for a backport onto the 4.7 branch.
Comment 8 David Edelsohn 2013-02-06 22:25:21 UTC
Go ahead and backport it to 4.7 branch.
Comment 9 Alan Modra 2013-02-07 01:39:29 UTC
Author: amodra
Date: Thu Feb  7 01:39:21 2013
New Revision: 195834

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195834
Log:
	PR target/53040
	* config/rs6000/rs6000.c (rs6000_savres_strategy): When using
	static chain, set REST_INLINE_FPRS too.


Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/rs6000/rs6000.c