aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface/decl.cc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2022-04-12 23:34:48 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-19 14:05:33 +0000
commit9aa9ba95ea3d4800974135da85fd4d9cd310b69e (patch)
treeeba33c668f8d7fc1dd87ab2a9d8e80c1c1cd40b7 /gcc/ada/gcc-interface/decl.cc
parente4c84b82c5f903de6911157281a837481bca780e (diff)
downloadgcc-9aa9ba95ea3d4800974135da85fd4d9cd310b69e.zip
gcc-9aa9ba95ea3d4800974135da85fd4d9cd310b69e.tar.gz
gcc-9aa9ba95ea3d4800974135da85fd4d9cd310b69e.tar.bz2
[Ada] Avoid copy operation for returns involving function calls
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Constant>: Deal with a constant related to a return in a function specially. * gcc-interface/trans.cc (Call_to_gnu): Use return slot optimization if the target is a return object. (gnat_to_gnu) <N_Object_Declaration>: Deal with a constant related to a return in a function specially.
Diffstat (limited to 'gcc/ada/gcc-interface/decl.cc')
-rw-r--r--gcc/ada/gcc-interface/decl.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 2d9b41f..50d17f7 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -630,6 +630,17 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
break;
case E_Constant:
+ /* If this is a constant related to a return in a function returning by
+ invisible reference without expression, get the return object. */
+ if (Is_Related_To_Func_Return (gnat_entity)
+ && current_function_decl
+ && TREE_ADDRESSABLE (TREE_TYPE (current_function_decl))
+ && !gnu_expr)
+ {
+ gnu_decl = DECL_RESULT (current_function_decl);
+ break;
+ }
+
/* Ignore constant definitions already marked with the error node. See
the N_Object_Declaration case of gnat_to_gnu for the rationale. */
if (definition