https://gcc.gnu.org/g:8bb19dbeda7fb947c52edfbf74462316e1341c6c

commit r17-929-g8bb19dbeda7fb947c52edfbf74462316e1341c6c
Author: Viljar Indus <[email protected]>
Date:   Mon Mar 9 16:33:19 2026 +0200

    ada: Refactor Inline_Static_Function_Call
    
    gcc/ada/ChangeLog:
    
            * inline.adb (Inline_Static_Function_Call): Reduce source code 
nesting.
            * inline.ads (Inline_Static_Function_Call): Likewise.

Diff:
---
 gcc/ada/inline.adb | 89 ++++++++++++++++++++++++++----------------------------
 gcc/ada/inline.ads | 13 ++++----
 2 files changed, 50 insertions(+), 52 deletions(-)

diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index 94ba3b479fab..7d7eff6c91b1 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -46,7 +46,6 @@ with Sem_Ch10;       use Sem_Ch10;
 with Sem_Ch12;       use Sem_Ch12;
 with Sem_Prag;       use Sem_Prag;
 with Sem_Res;        use Sem_Res;
-with Sem_Util;       use Sem_Util;
 with Sinfo.Nodes;    use Sinfo.Nodes;
 with Sinfo.Utils;    use Sinfo.Utils;
 with Sinput;         use Sinput;
@@ -4716,6 +4715,10 @@ package body Inline is
 
    procedure Inline_Static_Function_Call (N : Node_Id; Subp : Entity_Id) is
 
+      Decls        : constant List_Id := New_List;
+      Func_Expr    : constant Node_Id :=
+        Expression_Of_Expression_Function (Subp);
+      Expr_Copy    : constant Node_Id := New_Copy_Tree (Func_Expr);
       S_Adjustment : Sloc_Adjustment;
 
       function Adjust_Sloc (Nod : Node_Id) return Traverse_Result;
@@ -4776,70 +4779,64 @@ package body Inline is
    --  Start of processing for Inline_Static_Function_Call
 
    begin
-      pragma Assert (Is_Static_Function_Call (N));
+      --  Register the call in the list of inlined calls
 
-      declare
-         Decls     : constant List_Id := New_List;
-         Func_Expr : constant Node_Id :=
-                       Expression_Of_Expression_Function (Subp);
-         Expr_Copy : constant Node_Id := New_Copy_Tree (Func_Expr);
+      Append_New_Elmt (N, To => Inlined_Calls);
 
-      begin
-         --  Create a mapping from formals to actuals, also creating temps in
-         --  Decls, when needed, to hold the actuals.
+      --  Create a mapping from formals to actuals, also creating temps in
+      --  Decls, when needed, to hold the actuals.
 
-         Establish_Actual_Mapping_For_Inlined_Call (N, Subp, Decls, Func_Expr);
+      Establish_Actual_Mapping_For_Inlined_Call (N, Subp, Decls, Func_Expr);
 
-         --  Calculate the Adjustment for the inlined call
+      --  Calculate the Adjustment for the inlined call
 
-         Create_Instantiation_Source
-           (N, Subp, S_Adjustment, Inlined_Body => True);
+      Create_Instantiation_Source
+        (N, Subp, S_Adjustment, Inlined_Body => True);
 
-         --  Ensure that the copy has the same parent as the call (this seems
-         --  to matter when GNATprove_Mode is set and there are nested static
-         --  calls; prevents blowups in Insert_Actions, though it's not clear
-         --  exactly why this is needed???).
+      --  Ensure that the copy has the same parent as the call (this seems
+      --  to matter when GNATprove_Mode is set and there are nested static
+      --  calls; prevents blowups in Insert_Actions, though it's not clear
+      --  exactly why this is needed???).
 
-         Set_Parent (Expr_Copy, Parent (N));
+      Set_Parent (Expr_Copy, Parent (N));
 
-         Insert_Actions (N, Decls);
+      Insert_Actions (N, Decls);
 
-         --  Now substitute actuals for their corresponding formal references
-         --  within the expression.
+      --  Now substitute actuals for their corresponding formal references
+      --  within the expression.
 
-         Replace_Formals (Expr_Copy);
+      Replace_Formals (Expr_Copy);
 
-         Adjust_Slocs (Expr_Copy);
+      Adjust_Slocs (Expr_Copy);
 
-         --  Apply a qualified expression with the function's result subtype,
-         --  to ensure that we check the expression against any constraint
-         --  or predicate, which will cause the call to be illegal if the
-         --  folded expression doesn't satisfy them. (The predicate case
-         --  might not get checked if the subtype hasn't been frozen yet,
-         --  which can happen if this static expression happens to be what
-         --  causes the freezing, because Has_Static_Predicate doesn't get
-         --  set on the subtype until it's frozen and Build_Predicates is
-         --  called. It's not clear how to address this case. ???)
+      --  Apply a qualified expression with the function's result subtype,
+      --  to ensure that we check the expression against any constraint
+      --  or predicate, which will cause the call to be illegal if the
+      --  folded expression doesn't satisfy them. (The predicate case
+      --  might not get checked if the subtype hasn't been frozen yet,
+      --  which can happen if this static expression happens to be what
+      --  causes the freezing, because Has_Static_Predicate doesn't get
+      --  set on the subtype until it's frozen and Build_Predicates is
+      --  called. It's not clear how to address this case. ???)
 
-         Rewrite (Expr_Copy,
-           Make_Qualified_Expression (Sloc (Expr_Copy),
-             Subtype_Mark =>
-               New_Occurrence_Of (Etype (N), Sloc (Expr_Copy)),
-             Expression =>
-               Relocate_Node (Expr_Copy)));
+      Rewrite
+        (Expr_Copy,
+         Make_Qualified_Expression
+           (Sloc         => Sloc (Expr_Copy),
+            Subtype_Mark => New_Occurrence_Of (Etype (N), Sloc (Expr_Copy)),
+            Expression   => Relocate_Node (Expr_Copy)));
 
-         Set_Etype (Expr_Copy, Etype (N));
+      Set_Etype (Expr_Copy, Etype (N));
 
-         Analyze_And_Resolve (Expr_Copy, Etype (N));
+      Analyze_And_Resolve (Expr_Copy, Etype (N));
 
-         --  Finally rewrite the function call as the folded static result
+      --  Finally rewrite the function call as the folded static result
 
-         Rewrite (N, Expr_Copy);
+      Rewrite (N, Expr_Copy);
 
-         --  Cleanup mapping between formals and actuals for other expansions
+      --  Cleanup mapping between formals and actuals for other expansions
 
-         Reset_Actual_Mapping_For_Inlined_Call (Subp);
-      end;
+      Reset_Actual_Mapping_For_Inlined_Call (Subp);
    end Inline_Static_Function_Call;
 
    ------------------------
diff --git a/gcc/ada/inline.ads b/gcc/ada/inline.ads
index 4b6814212381..bc21838b4321 100644
--- a/gcc/ada/inline.ads
+++ b/gcc/ada/inline.ads
@@ -42,10 +42,11 @@
 --  Inline_Always subprograms, but there are fewer restrictions on the source
 --  of subprograms.
 
-with Opt;    use Opt;
-with Sem;    use Sem;
-with Types;  use Types;
-with Warnsw; use Warnsw;
+with Opt;      use Opt;
+with Sem;      use Sem;
+with Sem_Util; use Sem_Util;
+with Types;    use Types;
+with Warnsw;   use Warnsw;
 
 package Inline is
 
@@ -248,8 +249,8 @@ package Inline is
    --  Check a list of statements, Stats, that make inlining of Subp not
    --  worthwhile, including any tasking statement, nested at any level.
 
-   procedure Inline_Static_Function_Call
-     (N : Node_Id; Subp : Entity_Id);
+   procedure Inline_Static_Function_Call (N : Node_Id; Subp : Entity_Id)
+   with Pre => Is_Static_Function_Call (N);
    --  Evaluate static call to a static function Subp, substituting actuals in
    --  place of references to their corresponding formals and rewriting the
    --  call N as a fully folded and static result expression.

Reply via email to