From: Piotr Trojanek <troja...@adacore.com> 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. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/inline.adb | 35 +---------------------------------- gcc/ada/sem_util.adb | 2 +- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index 72b998961be..e8eeebd2d00 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -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); diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index af7e48b1eca..4e3c6255e31 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -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 -- 2.43.0