aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-12-10 10:24:47 +0100
committerMarc Poulhiès <dkm@gcc.gnu.org>2025-01-07 13:33:35 +0100
commit980415be73a4c762302eeba0813e435116bccc70 (patch)
tree85d3f57c601dfca3b5d6f633182b5ca15173e34a /gcc
parenta80bb3525e6e3596e025399691dc7789268fffe2 (diff)
downloadgcc-980415be73a4c762302eeba0813e435116bccc70.zip
gcc-980415be73a4c762302eeba0813e435116bccc70.tar.gz
gcc-980415be73a4c762302eeba0813e435116bccc70.tar.bz2
ada: Do not create temporaries for initialization statements
Assignment statements marked with the No_Ctrl_Actions or No_Finalize_Actions flag are initialization statements and, therefore, no temporaries are needed to hold the value of the right-hand side for them. gcc/ada/ChangeLog: * gcc-interface/trans.cc (Call_to_gnu): Always use the return slot optimization if the parent node is an initialization statement. (gnat_to_gnu) <N_Assignment_Statement>: Build an INIT_EXPR instead of a MODIFY_EXPR if this is an initialization statement.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/gcc-interface/trans.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index cda73d5..b65a846 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -5517,10 +5517,17 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target,
gigi_checking_assert (!Do_Range_Check (gnat_node));
+ /* If the parent is an initialization statement, we can use the
+ return slot optimization. */
+ if (Nkind (gnat_parent) == N_Assignment_Statement
+ && (No_Ctrl_Actions (gnat_parent)
+ || No_Finalize_Actions (gnat_parent)))
+ op_code = INIT_EXPR;
+
/* ??? If the return type has variable size, then force the return
slot optimization as we would not be able to create a temporary.
That's what has been done historically. */
- if (return_type_with_variable_size_p (gnu_result_type))
+ else if (return_type_with_variable_size_p (gnu_result_type))
op_code = INIT_EXPR;
/* If this is a call to a pure function returning an array of scalar
@@ -7811,6 +7818,12 @@ gnat_to_gnu (Node_Id gnat_node)
= build_unary_op (ADDR_EXPR, TREE_TYPE (arg), gnu_lhs);
}
+ /* If the statement is an initialization, build one too. */
+ else if (No_Ctrl_Actions (gnat_node)
+ || No_Finalize_Actions (gnat_node))
+ gnu_result
+ = build_binary_op (INIT_EXPR, NULL_TREE, gnu_lhs, gnu_rhs);
+
/* Otherwise build a regular assignment. */
else
gnu_result