https://gcc.gnu.org/g:ac357a72ddc6d558546fd610739441be3fefd619
commit r16-2338-gac357a72ddc6d558546fd610739441be3fefd619 Author: Marc Poulhiès <poulh...@adacore.com> Date: Fri Jun 20 16:10:25 2025 +0200 ada: Do not inline function returning on the secondary stack When inlining function calls that return on the secondary stack used as function actual or in a return statement, the compiler creates an invalid GNAT Tree with a variable of an unconstrained type without an initializer. Also add an extra assertion to catch problematic cases directly in Expand_Inlined_Call. gcc/ada/ChangeLog: * exp_ch6.adb (Convert): Do not call Expand_Inlined_Call for unsupported cases. * inline.adb (Expand_Inlined_Call): Add assert to catch unsupported case. Co-authored-by: Eric Botcazou <botca...@adacore.com> Diff: --- gcc/ada/exp_ch6.adb | 6 ++++++ gcc/ada/inline.adb | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index c24c8c63ef1f..6ea96d7498a6 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -5227,6 +5227,10 @@ package body Exp_Ch6 is -- also Build_Renamed_Body) cannot be expanded here because this may -- give rise to order-of-elaboration issues for the types of the -- parameters of the subprogram, if any. + -- + -- Expand_Inlined_Call procedure does not support the frontend + -- inlining of calls that return unconstrained types used as actuals + -- or in return statements. elsif Present (Unit_Declaration_Node (Subp)) and then Nkind (Unit_Declaration_Node (Subp)) = @@ -5235,6 +5239,8 @@ package body Exp_Ch6 is and then Nkind (Body_To_Inline (Unit_Declaration_Node (Subp))) not in N_Entity + and then Nkind (Parent (N)) /= N_Function_Call + and then Nkind (Parent (N)) /= N_Simple_Return_Statement then Expand_Inlined_Call (Call_Node, Subp, Orig_Subp); diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index e8eeebd2d002..5e2f033b913d 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -3797,6 +3797,17 @@ package body Inline is and then Is_Unc; end if; + -- Inlining function calls returning an object of unconstrained type as + -- function actuals or in a return statement is not supported: a + -- temporary variable will be declared of unconstrained type without + -- initializing expression. + + pragma Assert + (not Uses_Back_End + or else Nkind (Parent (N)) not in + N_Function_Call | N_Simple_Return_Statement + or else not Is_Unc); + -- Check for an illegal attempt to inline a recursive procedure. If the -- subprogram has parameters this is detected when trying to supply a -- binding for parameters that already have one. For parameterless