https://gcc.gnu.org/g:1cbf6f23b304a26c03b1521d028efae7e8acd1b1
commit r16-8972-g1cbf6f23b304a26c03b1521d028efae7e8acd1b1 Author: Denis Mazzucato <[email protected]> Date: Mon Dec 22 13:44:41 2025 +0100 ada: Fix spurious range check for out mode scalars in class-wide preconditions This patch fixes a spurious range check that was generated for out mode scalars after a class-wide precondition call. This issue was not present in static preconditions, but only in dynamic ones. This patch refactors the two helper call builders into the same to ensure the same processing of actuals. gcc/ada/ChangeLog: * exp_ch6.adb (Build_Helper_Call): Refactor code to handle both static and dynamic precondition calls in the same way. Diff: --- gcc/ada/exp_ch6.adb | 69 ++++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 54 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index eb552ea26376..f96c6bc8d1ee 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -8295,19 +8295,14 @@ package body Exp_Ch6 is procedure Install_Class_Preconditions_Check (Call_Node : Node_Id) is Loc : constant Source_Ptr := Sloc (Call_Node); - function Build_Dynamic_Check_Helper_Call return Node_Id; - -- Build call to the helper runtime function of the nearest ancestor - -- of the target subprogram that dynamically evaluates the merged - -- or-else preconditions. - function Build_Error_Message (Subp_Id : Entity_Id) return Node_Id; -- Build message associated with the class-wide precondition of Subp_Id -- indicating the call that caused it. - function Build_Static_Check_Helper_Call return Node_Id; + function Build_Helper_Call (Dynamic : Boolean) return Node_Id; -- Build call to the helper runtime function of the nearest ancestor - -- of the target subprogram that dynamically evaluates the merged - -- or-else preconditions. + -- of the target subprogram that statically or dynamically (depending on + -- the Dynamic flag) evaluates the merged or-else preconditions. function Class_Preconditions_Subprogram (Spec_Id : Entity_Id; @@ -8320,39 +8315,6 @@ package body Exp_Ch6 is -- preconditions; return Empty when not available (which means that no -- preconditions check is required). - ------------------------------------- - -- Build_Dynamic_Check_Helper_Call -- - ------------------------------------- - - function Build_Dynamic_Check_Helper_Call return Node_Id is - Spec_Id : constant Entity_Id := Entity (Name (Call_Node)); - CW_Subp : constant Entity_Id := - Class_Preconditions_Subprogram (Spec_Id, - Dynamic => True); - Helper_Id : constant Entity_Id := - Dynamic_Call_Helper (CW_Subp); - Actuals : constant List_Id := New_List; - A : Node_Id := First_Actual (Call_Node); - - begin - while Present (A) loop - - -- Ensure that the evaluation of the actuals will not produce - -- side effects. - - Remove_Side_Effects (A); - - Append_To (Actuals, New_Copy_Tree (A)); - - Next_Actual (A); - end loop; - - return - Make_Function_Call (Loc, - Name => New_Occurrence_Of (Helper_Id, Loc), - Parameter_Associations => Actuals); - end Build_Dynamic_Check_Helper_Call; - ------------------------- -- Build_Error_Message -- ------------------------- @@ -8434,11 +8396,11 @@ package body Exp_Ch6 is return Make_String_Literal (Loc, Name_Buffer (1 .. Name_Len)); end Build_Error_Message; - ------------------------------------ - -- Build_Static_Check_Helper_Call -- - ------------------------------------ + ----------------------- + -- Build_Helper_Call -- + ----------------------- - function Build_Static_Check_Helper_Call return Node_Id is + function Build_Helper_Call (Dynamic : Boolean) return Node_Id is Actuals : constant List_Id := New_List; A : Node_Id; Helper_Id : Entity_Id; @@ -8456,11 +8418,14 @@ package body Exp_Ch6 is -- Common case else - CW_Subp := Class_Preconditions_Subprogram (Spec_Id, - Dynamic => False); + CW_Subp := Class_Preconditions_Subprogram (Spec_Id, Dynamic); end if; - Helper_Id := Static_Call_Helper (CW_Subp); + if Dynamic then + Helper_Id := Dynamic_Call_Helper (CW_Subp); + else + Helper_Id := Static_Call_Helper (CW_Subp); + end if; F := First_Formal (Helper_Id); A := First_Actual (Call_Node); @@ -8489,7 +8454,7 @@ package body Exp_Ch6 is Make_Function_Call (Loc, Name => New_Occurrence_Of (Helper_Id, Loc), Parameter_Associations => Actuals); - end Build_Static_Check_Helper_Call; + end Build_Helper_Call; ------------------------------------ -- Class_Preconditions_Subprogram -- @@ -8632,11 +8597,7 @@ package body Exp_Ch6 is -- Build and install the check - if Dynamic_Check then - Cond := Build_Dynamic_Check_Helper_Call; - else - Cond := Build_Static_Check_Helper_Call; - end if; + Cond := Build_Helper_Call (Dynamic_Check); if Exception_Locations_Suppressed then Fail :=
