]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Remove wrong optimization in frontend inlining of procedure calls
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 29 Apr 2025 08:34:04 +0000 (10:34 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 1 Jul 2025 08:29:39 +0000 (10:29 +0200)
When using obsolete frontend inlining (switch -gnatN), we must always rewrite
the procedure call into a single block node. Otherwise, the copy-back of
parameters passed by-copy is inserted before the inlined procedure body, which
causes wrong code to be generated.

gcc/ada/ChangeLog:

* inline.adb (Rewrite_Procedure_Call): Replace with a simple rewriting
of procedure call into a single block node, i.e. remove broken
optimization.
* sem_util.adb (Next_Actual): Adapt GNATprove-specific code that peeks
into inlined calls.

gcc/ada/inline.adb
gcc/ada/sem_util.adb

index 72b998961be6cfbfb1f708780dc29c3a505cd56c..e8eeebd2d002d408bd05b6803dacd0d8e0b8b2c8 100644 (file)
@@ -3397,10 +3397,6 @@ package body Inline is
       --  If the function body is a single expression, replace call with
       --  expression, else insert block appropriately.
 
-      procedure Rewrite_Procedure_Call (N : Node_Id; Blk : Node_Id);
-      --  If procedure body has no local variables, inline body without
-      --  creating block, otherwise rewrite call with block.
-
       ---------------------
       -- Make_Exit_Label --
       ---------------------
@@ -3785,35 +3781,6 @@ package body Inline is
          end if;
       end Rewrite_Function_Call;
 
-      ----------------------------
-      -- Rewrite_Procedure_Call --
-      ----------------------------
-
-      procedure Rewrite_Procedure_Call (N : Node_Id; Blk : Node_Id) is
-         HSS : constant Node_Id := Handled_Statement_Sequence (Blk);
-
-      begin
-         --  If there is a transient scope for N, this will be the scope of the
-         --  actions for N, and the statements in Blk need to be within this
-         --  scope. For example, they need to have visibility on the constant
-         --  declarations created for the formals.
-
-         --  If N needs no transient scope, and if there are no declarations in
-         --  the inlined body, we can do a little optimization and insert the
-         --  statements for the body directly after N, and rewrite N to a
-         --  null statement, instead of rewriting N into a full-blown block
-         --  statement.
-
-         if not Scope_Is_Transient
-           and then Is_Empty_List (Declarations (Blk))
-         then
-            Insert_List_After (N, Statements (HSS));
-            Rewrite (N, Make_Null_Statement (Loc));
-         else
-            Rewrite (N, Blk);
-         end if;
-      end Rewrite_Procedure_Call;
-
    --  Start of processing for Expand_Inlined_Call
 
    begin
@@ -4273,7 +4240,7 @@ package body Inline is
       end;
 
       if Ekind (Subp) = E_Procedure then
-         Rewrite_Procedure_Call (N, Blk);
+         Rewrite (N, Blk);
 
       else
          Rewrite_Function_Call (N, Blk);
index af7e48b1eca9a2c1ebd9cf35624d4e2f99fe8552..4e3c6255e31b75f67877355cfecbca11d57548c0 100644 (file)
@@ -25019,7 +25019,7 @@ package body Sem_Util is
             --  In case of a call rewritten in GNATprove mode while "inlining
             --  for proof" go to the original call.
 
-            elsif Nkind (Par) = N_Null_Statement then
+            elsif Nkind (Par) in N_Null_Statement | N_Block_Statement then
                pragma Assert
                  (GNATprove_Mode
                     and then