From: Eric Botcazou <ebotca...@adacore.com> If an actual parameter that is a type conversion is passed by reference but not addressable, the temporary that is created and whose address is passed instead may need to be in the target type of the conversion to fulfill the requirements of strict aliasing.
gcc/ada/ChangeLog: * gcc-interface/trans.cc (Call_to_gnu): If the formal is passed by reference and the actual is a type conversion but not addressable, create the temporary in the target type of the conversion if this is needed to enforce strict aliasing. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/trans.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index 93f67404ddb..5f8a18eebb7 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -5010,9 +5010,12 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, TREE_TYPE (gnu_name)))) gnu_name = convert (gnu_name_type, gnu_name); - /* If the temporary is created because of aliasing considerations, + /* If the temporary is created because of aliasing considerations, + or would have been so created if the actual was addressable, it must be in the target type of the (unchecked) conversion. */ - if (aliasing) + if (aliasing + || (node_is_type_conversion (gnat_actual) + && !aliasable_p (gnu_name, gnu_actual_type))) { if (Nkind (gnat_actual) == N_Unchecked_Type_Conversion) gnu_name = unchecked_convert (gnu_actual_type, gnu_name, -- 2.43.0