When post call actions are created for a call to a function with a
result of a controlled type, such as for performing an invariant check
on a parameter with mode out or in out, the compiler can violate an
assertion (or crash with a Storage_Error) due to not recognizing the
expanded call as a function call. Calls to functions with controlled
results can be rewritten as an explicit dereference, and that case is
now checked for when processing post-call actions.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_ch6.adb (Insert_Post_Call_Actions): Test for
N_Explicit_Dereference as part of the existing test for function
calls.diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -8360,9 +8360,12 @@ package body Exp_Ch6 is
-- The write-back of (in)-out parameters is handled by the back-end,
-- but the constraint checks generated when subtypes of formal and
-- actual don't match must be inserted in the form of assignments.
+ -- Also do this in the case of explicit dereferences, which can occur
+ -- due to rewritings of function calls with controlled results.
if Nkind (N) = N_Function_Call
or else Nkind (Original_Node (N)) = N_Function_Call
+ or else Nkind (N) = N_Explicit_Dereference
then
pragma Assert (Ada_Version >= Ada_2012);
-- Functions with '[in] out' parameters are only allowed in Ada