aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2023-06-21 00:50:40 +0200
committerEric Botcazou <ebotcazou@adacore.com>2023-09-27 10:16:28 +0200
commitff365f7c519c953a4131ef7aabb1e0aa39dca3a8 (patch)
tree66752b28b42c67115ece955f44e1027fbcaa6c2a /gcc
parent02a29fdccbb8d18bc96bdfdcdcf1b4e19102cc2d (diff)
downloadgcc-ff365f7c519c953a4131ef7aabb1e0aa39dca3a8.zip
gcc-ff365f7c519c953a4131ef7aabb1e0aa39dca3a8.tar.gz
gcc-ff365f7c519c953a4131ef7aabb1e0aa39dca3a8.tar.bz2
ada: Fix bad interaction between inlining and thunk generation
This may cause the type of the RESULT_DECL of a function which returns by invisible reference to be turned into a reference type twice. gcc/ada/ * gcc-interface/trans.cc (Subprogram_Body_to_gnu): Add guard to the code turning the type of the RESULT_DECL into a reference type. (maybe_make_gnu_thunk): Use a more precise guard in the same case.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/gcc-interface/trans.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 5fc1a26..c43af16 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -3894,8 +3894,11 @@ Subprogram_Body_to_gnu (Node_Id gnat_node)
gnu_return_var_elmt = NULL_TREE;
/* If the function returns by invisible reference, make it explicit in the
- function body. See gnat_to_gnu_subprog_type for more details. */
- if (TREE_ADDRESSABLE (gnu_subprog_type))
+ function body, but beware that maybe_make_gnu_thunk may already have done
+ it if the function is inlined across units. See gnat_to_gnu_subprog_type
+ for more details. */
+ if (TREE_ADDRESSABLE (gnu_subprog_type)
+ && TREE_CODE (TREE_TYPE (gnu_result_decl)) != REFERENCE_TYPE)
{
TREE_TYPE (gnu_result_decl)
= build_reference_type (TREE_TYPE (gnu_result_decl));
@@ -11047,7 +11050,7 @@ maybe_make_gnu_thunk (Entity_Id gnat_thunk, tree gnu_thunk)
same transformation as Subprogram_Body_to_gnu here. */
if (TREE_ADDRESSABLE (TREE_TYPE (gnu_target))
&& DECL_EXTERNAL (gnu_target)
- && !POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (gnu_target))))
+ && TREE_CODE (TREE_TYPE (DECL_RESULT (gnu_target))) != REFERENCE_TYPE)
{
TREE_TYPE (DECL_RESULT (gnu_target))
= build_reference_type (TREE_TYPE (DECL_RESULT (gnu_target)));