]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Do not inline function returning on the secondary stack
authorMarc Poulhiès <poulhies@adacore.com>
Fri, 20 Jun 2025 14:10:25 +0000 (16:10 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 18 Jul 2025 08:29:49 +0000 (10:29 +0200)
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 <botcazou@adacore.com>
gcc/ada/exp_ch6.adb
gcc/ada/inline.adb

index c24c8c63ef1fb06124e1a542507c2da2655f495b..6ea96d7498a627933ba65c4b7d673c7d4a97c2d5 100644 (file)
@@ -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);
 
index e8eeebd2d002d408bd05b6803dacd0d8e0b8b2c8..5e2f033b913d8fe83c9924e9f4edb16270a7ee09 100644 (file)
@@ -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