diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2024-03-12 17:56:00 +0100 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2024-05-21 09:27:57 +0200 |
commit | d851e08ba97f5d0671711763f6a7d4c94afb8457 (patch) | |
tree | 3a04c43ec6b2c1fbbb6a655513ce47384b7dee09 /gcc/ada/gcc-interface | |
parent | f20a57edefe0cb185e57f82a15e887887b98d3ab (diff) | |
download | gcc-d851e08ba97f5d0671711763f6a7d4c94afb8457.zip gcc-d851e08ba97f5d0671711763f6a7d4c94afb8457.tar.gz gcc-d851e08ba97f5d0671711763f6a7d4c94afb8457.tar.bz2 |
ada: Make detection of useless copy for return more robust
In the return-by-invisible-reference case, the return object of an extended
return statement is allocated directly on the return stack and, therefore,
the copy operation on return is useless. The code detecting this was not
robust enough and missed some complex cases.
gcc/ada/
* gcc-interface/trans.cc (gnat_to_gnu) <N_Simple_Return_Statement>:
In the return-by-invisible-reference case, remove conversions before
looking for a dereference in the return values and building the test
protecting against a useless copy operation.
Diffstat (limited to 'gcc/ada/gcc-interface')
-rw-r--r-- | gcc/ada/gcc-interface/trans.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index a6b86ec..4ae599b 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -7767,11 +7767,12 @@ gnat_to_gnu (Node_Id gnat_node) gnu_result = build2 (INIT_EXPR, void_type_node, gnu_ret_deref, gnu_ret_val); /* Avoid a useless copy with __builtin_return_slot. */ - if (INDIRECT_REF_P (gnu_ret_val)) + tree gnu_inner_val = remove_conversions (gnu_ret_val, false); + if (INDIRECT_REF_P (gnu_inner_val)) gnu_result = build3 (COND_EXPR, void_type_node, fold_build2 (NE_EXPR, boolean_type_node, - TREE_OPERAND (gnu_ret_val, 0), + TREE_OPERAND (gnu_inner_val, 0), gnu_ret_obj), gnu_result, NULL_TREE); add_stmt_with_node (gnu_result, gnat_node); |