diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2024-04-29 09:48:48 +0200 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2024-06-14 09:34:51 +0200 |
commit | 83061c80d29f71b1aa07664fd129af6542c9fc83 (patch) | |
tree | 844d6692f45cfa8a463f7e54a71e8fb3c77f2977 /gcc/ada | |
parent | 02b7f6862723fc9f3c73a38dc9b7c518cfdf5069 (diff) | |
download | gcc-83061c80d29f71b1aa07664fd129af6542c9fc83.zip gcc-83061c80d29f71b1aa07664fd129af6542c9fc83.tar.gz gcc-83061c80d29f71b1aa07664fd129af6542c9fc83.tar.bz2 |
ada: Fix return mechanism reported by -gnatRm
The return mechanism of functions is reported when the -gnatRm switch is
specified, but it is incorrect when the result type is not a by-reference
type in the language sense but is nevertheless returned by reference.
gcc/ada/
* gcc-interface/decl.cc: Include function.h.
(gnat_to_gnu_param): Minor comment tweaks.
(gnat_to_gnu_subprog_type): Take into account the default for the
computation of the return mechanism. Give a warning if a by-copy
specified mechanism cannot be honored.
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/gcc-interface/decl.cc | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index 2398374..aa31a88 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -27,6 +27,7 @@ #include "system.h" #include "coretypes.h" #include "target.h" +#include "function.h" #include "tree.h" #include "gimple-expr.h" #include "stringpool.h" @@ -5703,6 +5704,7 @@ gnat_to_gnu_param (Entity_Id gnat_param, tree gnu_param_type, bool first, input_location = saved_location; + /* Warn if we are asked to pass by copy but cannot. */ if (mech == By_Copy && (by_ref || by_component_ptr)) post_error ("??cannot pass & by copy", gnat_param); @@ -5735,12 +5737,13 @@ gnat_to_gnu_param (Entity_Id gnat_param, tree gnu_param_type, bool first, DECL_RESTRICTED_ALIASING_P (gnu_param) = restricted_aliasing_p; Sloc_to_locus (Sloc (gnat_param), &DECL_SOURCE_LOCATION (gnu_param)); - /* If no Mechanism was specified, indicate what we're using, then - back-annotate it. */ + /* If no Mechanism was specified, indicate what we will use. */ if (mech == Default) mech = (by_ref || by_component_ptr) ? By_Reference : By_Copy; + /* Back-annotate the mechanism in all cases. */ Set_Mechanism (gnat_param, mech); + return gnu_param; } @@ -6129,11 +6132,6 @@ gnat_to_gnu_subprog_type (Entity_Id gnat_subprog, bool definition, associate_subprog_with_dummy_type (gnat_subprog, gnu_return_type); incomplete_profile_p = true; } - - if (kind == E_Function) - Set_Mechanism (gnat_subprog, return_by_direct_ref_p - || return_by_invisi_ref_p - ? By_Reference : By_Copy); } /* A procedure (something that doesn't return anything) shouldn't be @@ -6636,6 +6634,28 @@ gnat_to_gnu_subprog_type (Entity_Id gnat_subprog, bool definition, if (warn_shadow) post_error ("'G'C'C builtin not found for&!??", gnat_subprog); } + + /* Finally deal with the return mechanism for a function. */ + if (kind == E_Function) + { + /* We return by reference either if this is required by the semantics + of the language or if this is the default for the function. */ + const bool by_ref = return_by_direct_ref_p + || return_by_invisi_ref_p + || aggregate_value_p (gnu_return_type, gnu_type); + Mechanism_Type mech = Mechanism (gnat_subprog); + + /* Warn if we are asked to return by copy but cannot. */ + if (mech == By_Copy && by_ref) + post_error ("??cannot return from & by copy", gnat_subprog); + + /* If no mechanism was specified, indicate what we will use. */ + if (mech == Default) + mech = by_ref ? By_Reference : By_Copy; + + /* Back-annotate the mechanism in all cases. */ + Set_Mechanism (gnat_subprog, mech); + } } *param_list = gnu_param_list; |