https://gcc.gnu.org/g:980415be73a4c762302eeba0813e435116bccc70
commit r15-6646-g980415be73a4c762302eeba0813e435116bccc70 Author: Eric Botcazou <ebotca...@adacore.com> Date: Tue Dec 10 10:24:47 2024 +0100 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. Diff: --- gcc/ada/gcc-interface/trans.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index cda73d509e84..b65a846ee667 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