From 56f9cf9142a6f54fd692c409d0faed607e2cb873 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Fri, 21 Sep 2018 10:06:25 +0000 Subject: [PATCH] rs6000.c (rs6000_function_ok_for_sibcall): Return false if the call takes a static chain. * config/rs6000/rs6000.c (rs6000_function_ok_for_sibcall): Return false if the call takes a static chain. From-SVN: r264465 --- gcc/ChangeLog | 5 ++++ gcc/config/rs6000/rs6000.c | 6 +++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/nested-func-11.c | 34 +++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/nested-func-11.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a076b8816189..471a203d2958 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-09-21 Eric Botcazou + + * config/rs6000/rs6000.c (rs6000_function_ok_for_sibcall): Return false + if the call takes a static chain. + 2018-09-19 John David Anglin * config/pa/pa.md (atomic_storeqi): Restore deleted expander. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 365f006af626..d377e2429135 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -27793,6 +27793,12 @@ rs6000_function_ok_for_sibcall (tree decl, tree exp) { tree fntype; + /* The sibcall epilogue may clobber the static chain register. + ??? We could work harder and avoid that, but it's probably + not worth the hassle in practice. */ + if (CALL_EXPR_STATIC_CHAIN (exp)) + return false; + if (decl) fntype = TREE_TYPE (decl); else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 60ce73f3a3dc..55bf1c25c9c8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-09-21 Eric Botcazou + + * gcc.dg/nested-func-11.c: New test. + 2018-09-13 Paul Thomas Backported from trunk diff --git a/gcc/testsuite/gcc.dg/nested-func-11.c b/gcc/testsuite/gcc.dg/nested-func-11.c new file mode 100644 index 000000000000..01096b4147f6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/nested-func-11.c @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-omit-frame-pointer" } */ + +int __attribute__((noipa)) foo (int i) +{ + int a; + + void __attribute__((noipa)) nested2 (int i) + { + a = i; + } + + void __attribute__((noipa)) nested1 (int i) + { + int b[32]; + + for (int j = 0; j < 32; j++) + b[j] = i + j; + + nested2 (b[i]); + } + + nested1 (i); + + return a; +} + +int main (void) +{ + if (foo (4) != 8) + __builtin_abort (); + + return 0; +} -- 2.47.2