From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id A3F8E3858298; Fri, 4 Nov 2022 13:54:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3F8E3858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667570098; bh=hIf94UwY68IeLOQOv4bQiufRV0lVHN80LDk8T1oLnV0=; h=From:To:Subject:Date:From; b=Xr2vT3SwNuePTdmNUY+rAvfGBBpbzBq4KjtMtDuInUdrFCExsidmISe/GSDsqLuPk ypBYmGHQNiJcXU/krkao1CKzXs11WY7iWyS199UuS720n/3KPgV1VFu3A7a/OSpyx9 DKYAS94X5G0HlLIokJohSAjOfYjZKyy7RG5MEvgA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3674] ada: Avoid repeated iteration over private protected components X-Act-Checkin: gcc X-Git-Author: Piotr Trojanek X-Git-Refname: refs/heads/master X-Git-Oldrev: cb3c260460073bed267fae3ee970947a24858211 X-Git-Newrev: 5f780a2d02d0b7c92a75ce1f749ffcc15b90fa32 Message-Id: <20221104135458.A3F8E3858298@sourceware.org> Date: Fri, 4 Nov 2022 13:54:58 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5f780a2d02d0b7c92a75ce1f749ffcc15b90fa32 commit r13-3674-g5f780a2d02d0b7c92a75ce1f749ffcc15b90fa32 Author: Piotr Trojanek Date: Thu Sep 1 10:19:09 2022 +0200 ada: Avoid repeated iteration over private protected components The First_Entity/Next_Entity chain includes private entities, so there it no need to iterate starting both from First_Entity and First_Private_Entity. Code cleanup related to improved detection of references to uninitialized objects; behavior is unaffected. gcc/ada/ * sem_util.adb (Check_Components): Iterate using First/Next_Component_Or_Discriminant. (Has_Preelaborable_Initialization): Avoid repeated iteration with calls to Check_Components with First_Entity and First_Private_Entity. (Is_Independent_Object_Entity): Tune indentation. Diff: --- gcc/ada/sem_util.adb | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 9a7640b3147..536d5fadefb 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -13679,15 +13679,12 @@ package body Sem_Util is Exp : Node_Id; begin - -- Loop through entities of record or protected type + -- Loop through components and discriminants of record or protected + -- type. - Ent := E; + Ent := First_Component_Or_Discriminant (E); while Present (Ent) loop - -- We are interested only in components and discriminants - - Exp := Empty; - case Ekind (Ent) is when E_Component => @@ -13698,6 +13695,8 @@ package body Sem_Util is if Present (Declaration_Node (Ent)) then Exp := Expression (Declaration_Node (Ent)); + else + Exp := Empty; end if; when E_Discriminant => @@ -13710,7 +13709,7 @@ package body Sem_Util is Exp := Discriminant_Default_Value (Ent); when others => - goto Check_Next_Entity; + raise Program_Error; end case; -- A component has PI if it has no default expression and the @@ -13731,8 +13730,7 @@ package body Sem_Util is exit; end if; - <> - Next_Entity (Ent); + Next_Component_Or_Discriminant (Ent); end loop; end Check_Components; @@ -13842,7 +13840,7 @@ package body Sem_Util is -- If OK, check extension components (if any) if Has_PE and then Is_Record_Type (E) then - Check_Components (First_Entity (E)); + Check_Components (E); end if; -- Check specifically for 10.2.1(11.4/2) exception: a controlled type @@ -13882,7 +13880,7 @@ package body Sem_Util is elsif Is_Record_Type (E) then Has_PE := True; - Check_Components (First_Entity (E)); + Check_Components (E); -- Protected types must not have entries, and components must meet -- same set of rules as for record components. @@ -13892,8 +13890,7 @@ package body Sem_Util is Has_PE := False; else Has_PE := True; - Check_Components (First_Entity (E)); - Check_Components (First_Private_Entity (E)); + Check_Components (E); end if; -- Type System.Address always has preelaborable initialization @@ -18305,7 +18302,7 @@ package body Sem_Util is Is_Object (Id) and then (Is_Independent (Id) or else - Is_Independent (Etype (Id))); + Is_Independent (Etype (Id))); end Is_Independent_Object_Entity; -------------------------------------