From: Bob Duff Date: Sun, 8 Mar 2020 21:50:49 +0000 (-0400) Subject: [Ada] Disable unwanted warnings in Assertion_Policy(Ignore) mode X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b9daf13c9350cc02c120971a472092d474d63e8f;p=gcc.git [Ada] Disable unwanted warnings in Assertion_Policy(Ignore) mode 2020-06-10 Bob Duff gcc/ada/ * sem_prag.adb (Invariant): Remove the pragma removing code. It doesn't work to remove the pragma, because various flags are set during Build_Invariant_Procedure_Declaration and Build_Invariant_Procedure_Body that need to be set to avoid the spurious warnings. * exp_util.adb (Make_Invariant_Call): Avoid calling the invariant-checking procedure if the body is empty. This is an optimization. --- diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 7fce77a2d3a..5e186ec1ca4 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -2298,9 +2298,8 @@ package body Exp_Util is -- Generate: -- Invariant (_object ()); - -- Note that the invariant procedure may have a null body if - -- assertions are disabled or Assertion_Policy Ignore is in - -- effect. + -- The invariant procedure has a null body if assertions are + -- disabled or Assertion_Policy Ignore is in effect. if not Has_Null_Body (Proc_Id) then Append_New_To (Comp_Checks, @@ -9360,19 +9359,22 @@ package body Exp_Util is function Make_Invariant_Call (Expr : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (Expr); Typ : constant Entity_Id := Base_Type (Etype (Expr)); - - Proc_Id : Entity_Id; - - begin pragma Assert (Has_Invariants (Typ)); - - Proc_Id := Invariant_Procedure (Typ); + Proc_Id : constant Entity_Id := Invariant_Procedure (Typ); pragma Assert (Present (Proc_Id)); + begin + -- The invariant procedure has a null body if assertions are disabled or + -- Assertion_Policy Ignore is in effect. In that case, generate a null + -- statement instead of a call to the invariant procedure. - return - Make_Procedure_Call_Statement (Loc, - Name => New_Occurrence_Of (Proc_Id, Loc), - Parameter_Associations => New_List (Relocate_Node (Expr))); + if Has_Null_Body (Proc_Id) then + return Make_Null_Statement (Loc); + else + return + Make_Procedure_Call_Statement (Loc, + Name => New_Occurrence_Of (Proc_Id, Loc), + Parameter_Associations => New_List (Relocate_Node (Expr))); + end if; end Make_Invariant_Call; ------------------------ diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 2dfe9e06aba..d05b8fe2a8d 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -18607,20 +18607,6 @@ package body Sem_Prag is return; end if; - -- If invariants should be ignored, delete the pragma and then - -- return. We do this here, after checking for errors, and before - -- generating anything that has a run-time effect. - - if Present (Check_Policy_List) - and then - (Policy_In_Effect (Name_Invariant) = Name_Ignore - and then - Policy_In_Effect (Name_Type_Invariant) = Name_Ignore) - then - Rewrite (N, Make_Null_Statement (Loc)); - return; - end if; - -- A pragma that applies to a Ghost entity becomes Ghost for the -- purposes of legality checks and removal of ignored Ghost code.