summaryrefslogtreecommitdiffstats
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2022-04-12 21:56:35 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-19 14:05:30 +0000
commit8be71a90b15916a966553c47857e1579ca22d507 (patch)
treead3bac00daf7b04e370ceb3bcf73ea1ac1e28009 /gcc
parent[Ada] Fix invalid expanded code for entry families (diff)
downloadgcc-8be71a90b15916a966553c47857e1579ca22d507.tar.gz
gcc-8be71a90b15916a966553c47857e1579ca22d507.tar.bz2
gcc-8be71a90b15916a966553c47857e1579ca22d507.tar.xz
[Ada] Avoid copy operation for returns involving function calls
The underlying issue is that the front-end does not create transient scopes for return statements, so objects copied for these statements can never be finalized properly. gcc/ada/ * exp_ch6.adb (Expand_Call_Helper): Adjust comment. (Expand_Simple_Function_Return): For the case of a type which needs finalization and is returned on the primary stack, do not create a copy if the expression originates from a function call. * exp_ch7.adb (Transient Scope Management): Adjust comment. * exp_util.ads (Is_Related_To_Func_Return): Add WARNING line. * fe.h (Is_Related_To_Func_Return): Declare.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_ch6.adb6
-rw-r--r--gcc/ada/exp_ch7.adb13
-rw-r--r--gcc/ada/exp_util.ads2
-rw-r--r--gcc/ada/fe.h4
4 files changed, 12 insertions, 13 deletions
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index e95c6c5b5a7..deb514e188d 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -4899,8 +4899,8 @@ package body Exp_Ch6 is
4899 -- the return type is limited, then the context is initialization and 4899 -- the return type is limited, then the context is initialization and
4900 -- different processing applies. If the call is to a protected function, 4900 -- different processing applies. If the call is to a protected function,
4901 -- the expansion above will call Expand_Call recursively. Otherwise the 4901 -- the expansion above will call Expand_Call recursively. Otherwise the
4902 -- function call is transformed into a temporary which obtains the 4902 -- function call is transformed into a reference to the result that has
4903 -- result from the secondary stack. 4903 -- been built either on the return or the secondary stack.
4904 4904
4905 if Needs_Finalization (Etype (Subp)) then 4905 if Needs_Finalization (Etype (Subp)) then
4906 if not Is_Build_In_Place_Function_Call (Call_Node) 4906 if not Is_Build_In_Place_Function_Call (Call_Node)
@@ -7369,7 +7369,7 @@ package body Exp_Ch6 is
7369 7369
7370 if Present (Utyp) 7370 if Present (Utyp)
7371 and then Needs_Finalization (Utyp) 7371 and then Needs_Finalization (Utyp)
7372 and then not (Nkind (Exp) = N_Function_Call 7372 and then not (Exp_Is_Function_Call
7373 and then Needs_Finalization (Exp_Typ)) 7373 and then Needs_Finalization (Exp_Typ))
7374 then 7374 then
7375 declare 7375 declare
diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 0c53f326887..2d58f3bb4b6 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -109,18 +109,13 @@ package body Exp_Ch7 is
109 -- pass the address of a constrained object as the target object for the 109 -- pass the address of a constrained object as the target object for the
110 -- function result. 110 -- function result.
111 111
112 -- By allocating tagged results in the secondary stack a number of 112 -- By always allocating tagged results in the secondary stack, a couple of
113 -- implementation difficulties are avoided: 113 -- implementation difficulties are avoided:
114 114
115 -- - If it is a dispatching function call, the computation of the size of 115 -- - If this is a dispatching function call, the computation of the size
116 -- the result is possible but complex from the outside. 116 -- of the result is possible but complex from the outside.
117 117
118 -- - If the returned type is controlled, the assignment of the returned 118 -- - If the result type is class-wide, it is unconstrained anyway.
119 -- value to the anonymous object involves an Adjust, and we have no
120 -- easy way to access the anonymous object created by the back end.
121
122 -- - If the returned type is class-wide, this is an unconstrained type
123 -- anyway.
124 119
125 -- Furthermore, the small loss in efficiency which is the result of this 120 -- Furthermore, the small loss in efficiency which is the result of this
126 -- decision is not such a big deal because functions returning tagged types 121 -- decision is not such a big deal because functions returning tagged types
diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads
index de2180983f6..f3456b3f455 100644
--- a/gcc/ada/exp_util.ads
+++ b/gcc/ada/exp_util.ads
@@ -820,6 +820,8 @@ package Exp_Util is
820 -- Determine whether object Id is related to an expanded return statement. 820 -- Determine whether object Id is related to an expanded return statement.
821 -- The case concerned is "return Id.all;". 821 -- The case concerned is "return Id.all;".
822 822
823 -- WARNING: There is a matching C declaration of this subprogram in fe.h
824
823 function Is_Renamed_Object (N : Node_Id) return Boolean; 825 function Is_Renamed_Object (N : Node_Id) return Boolean;
824 -- Returns True if the node N is a renamed object. An expression is 826 -- Returns True if the node N is a renamed object. An expression is
825 -- considered to be a renamed object if either it is the Name of an object 827 -- considered to be a renamed object if either it is the Name of an object
diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h
index 4be9d94685e..bfd90543d54 100644
--- a/gcc/ada/fe.h
+++ b/gcc/ada/fe.h
@@ -183,9 +183,11 @@ extern Boolean Is_Init_Proc (Entity_Id);
183/* exp_util: */ 183/* exp_util: */
184 184
185#define Is_Fully_Repped_Tagged_Type exp_util__is_fully_repped_tagged_type 185#define Is_Fully_Repped_Tagged_Type exp_util__is_fully_repped_tagged_type
186#define Is_Related_To_Func_Return exp_util__is_related_to_func_return
186#define Find_Interface_Tag exp_util__find_interface_tag 187#define Find_Interface_Tag exp_util__find_interface_tag
187 188
188extern Boolean Is_Fully_Repped_Tagged_Type (Entity_Id); 189extern Boolean Is_Fully_Repped_Tagged_Type (Entity_Id);
190extern Boolean Is_Related_To_Func_Return (Entity_Id);
189extern Entity_Id Find_Interface_Tag (Entity_Id, Entity_Id); 191extern Entity_Id Find_Interface_Tag (Entity_Id, Entity_Id);
190 192
191/* lib: */ 193/* lib: */