]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix fallout of recent freezing change for expression functions
authorEric Botcazou <ebotcazou@adacore.com>
Sun, 18 Jan 2026 21:12:25 +0000 (22:12 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 25 May 2026 08:28:12 +0000 (10:28 +0200)
The change unnecessarily prevents the profile of all dispatching operations
from being frozen by their subprogram body, which exposes a weakness in the
implementation of freezing for generic units.  This just reverts that part.

gcc/ada/ChangeLog:

PR ada/93702
* exp_ch3.adb (Make_Controlling_Function_Wrappers): Revert latest
change.
* sem_ch12.adb (Analyze_One_Association): Remove redundant line.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Freeze the profile
again for bodies that are not generated from expression functions.

gcc/ada/exp_ch3.adb
gcc/ada/sem_ch12.adb
gcc/ada/sem_ch6.adb

index d1956c1a1bee6cefb673a3bdbec23a033c501f11..1b7b4aae653c49578ff8364a61a32aaa32eeb749 100644 (file)
@@ -11683,7 +11683,10 @@ package body Exp_Ch3 is
                 Null_Record_Present => True);
 
             --  GNATprove will use expression of an expression function as an
-            --  implicit postcondition.
+            --  implicit postcondition. GNAT will also benefit from expression
+            --  function to avoid premature freezing, but would struggle if we
+            --  added an expression function to freezing actions, so we create
+            --  the expanded form directly.
 
             if GNATprove_Mode then
                Func_Body :=
@@ -11702,6 +11705,7 @@ package body Exp_Ch3 is
                        Statements => New_List (
                          Make_Simple_Return_Statement (Loc,
                            Expression => Ext_Aggr))));
+               Set_Was_Expression_Function (Func_Body);
             end if;
 
             Append_To (Body_List, Func_Body);
index 402aa2164270878a187108356de5a702c0f59ce7..e25d9c67fceba00a83aaafb03155ab295affb1cc 100644 (file)
@@ -2455,7 +2455,6 @@ package body Sem_Ch12 is
             if Is_Expression_Function (Node (Elmt)) then
                Expr := New_Occurrence_Of (Node (Elmt), Sloc (N));
                Set_Comes_From_Source (Expr);
-               Set_Entity (Expr, Node (Elmt));
                Set_Parent (Expr, N);
                Freeze_Expression (Expr);
             else
index d898fb40997ce4742431986d86624336780e34d6..514ab6eb6181eeebc0028582d0ed7cd00c85296c 100644 (file)
@@ -3848,7 +3848,9 @@ package body Sem_Ch6 is
             Set_Has_Delayed_Freeze (Spec_Id);
             Create_Extra_Formals (Spec_Id, Related_Nod => N);
             Freeze_Before (N, Spec_Id,
-              Do_Freeze_Profile => not Is_Dispatching_Operation (Spec_Id));
+              Do_Freeze_Profile => not
+                (From_Expression_Function
+                  and then Is_Dispatching_Operation (Spec_Id)));
          end if;
       end if;