aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gnat.dg
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2020-09-14 17:24:32 +0200
committerEric Botcazou <ebotcazou@adacore.com>2020-09-14 17:38:39 +0200
commita7d8dcdf2f3cf9a801e655f2eec3967a3a3ba666 (patch)
treec8845d0fd0b213f1143e93ca46b864115f920cfb /gcc/testsuite/gnat.dg
parent863e8d53eb2940e2c8850e632afe427e164f53cf (diff)
downloadgcc-a7d8dcdf2f3cf9a801e655f2eec3967a3a3ba666.zip
gcc-a7d8dcdf2f3cf9a801e655f2eec3967a3a3ba666.tar.gz
gcc-a7d8dcdf2f3cf9a801e655f2eec3967a3a3ba666.tar.bz2
Fix dangling references in thunks at -O0
When a thunk cannot be emitted in assembly directly, expand_thunk generates regular GIMPLE code but unconditionally forces a tail call to the target of the thunk. That's theoretically OK because the thunk essentially forwards its parameters to the target, but in practice the RTL expander can spill parameters passed by reference on the stack in assign_parm_setup_reg. gcc/ChangeLog: * cgraphunit.c (cgraph_node::expand_thunk): Make sure to set cfun->tail_call_marked when forcing a tail call. * function.c (assign_parm_setup_reg): Always use a register to load a parameter passed by reference if cfun->tail_call_marked. gcc/testsuite/ChangeLog: * gnat.dg/thunk1.adb: New test. * gnat.dg/thunk1_pkg1.ads: New helper. * gnat.dg/thunk1_pkg2.ads: Likewise. * gnat.dg/thunk1_pkg2.adb: Likewise.
Diffstat (limited to 'gcc/testsuite/gnat.dg')
-rw-r--r--gcc/testsuite/gnat.dg/thunk1.adb9
-rw-r--r--gcc/testsuite/gnat.dg/thunk1_pkg1.ads7
-rw-r--r--gcc/testsuite/gnat.dg/thunk1_pkg2.adb10
-rw-r--r--gcc/testsuite/gnat.dg/thunk1_pkg2.ads14
4 files changed, 40 insertions, 0 deletions
diff --git a/gcc/testsuite/gnat.dg/thunk1.adb b/gcc/testsuite/gnat.dg/thunk1.adb
new file mode 100644
index 0000000..278e023
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/thunk1.adb
@@ -0,0 +1,9 @@
+-- { dg-do run }
+
+with Thunk1_Pkg1; use Thunk1_Pkg1;
+
+procedure Thunk1 is
+ D: Derived;
+begin
+ D.Op ("Message");
+end;
diff --git a/gcc/testsuite/gnat.dg/thunk1_pkg1.ads b/gcc/testsuite/gnat.dg/thunk1_pkg1.ads
new file mode 100644
index 0000000..edb3eac
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/thunk1_pkg1.ads
@@ -0,0 +1,7 @@
+with Thunk1_Pkg2; use Thunk1_Pkg2;
+
+package Thunk1_Pkg1 is
+
+ type Derived is new Ext with null record;
+
+end Thunk1_Pkg1;
diff --git a/gcc/testsuite/gnat.dg/thunk1_pkg2.adb b/gcc/testsuite/gnat.dg/thunk1_pkg2.adb
new file mode 100644
index 0000000..71ad45d
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/thunk1_pkg2.adb
@@ -0,0 +1,10 @@
+package body Thunk1_Pkg2 is
+
+ procedure Op (This : in out Ext; S : String) is
+ begin
+ if S /= "Message" then
+ raise Program_Error;
+ end if;
+ end;
+
+end Thunk1_Pkg2;
diff --git a/gcc/testsuite/gnat.dg/thunk1_pkg2.ads b/gcc/testsuite/gnat.dg/thunk1_pkg2.ads
new file mode 100644
index 0000000..82a48d5
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/thunk1_pkg2.ads
@@ -0,0 +1,14 @@
+package Thunk1_Pkg2 is
+
+ type Root is tagged record
+ I : Integer;
+ end record;
+
+ type Iface is interface;
+ procedure Op (This : in out Iface; S : String) is abstract;
+
+ type Ext is new Root and Iface with null record;
+
+ procedure Op (This : in out Ext; S : String);
+
+end Thunk1_Pkg2;