From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 00F3C3858433; Mon, 25 Oct 2021 15:09:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00F3C3858433 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-4683] [Ada] Simplify iteration of record components when expanding equality X-Act-Checkin: gcc X-Git-Author: Piotr Trojanek X-Git-Refname: refs/heads/master X-Git-Oldrev: 1ddc39479b999841e0b0e994a47bf3cec8a4e54e X-Git-Newrev: 234815d4c38608eb1bff20f68d6dd4c233f07725 Message-Id: <20211025150912.00F3C3858433@sourceware.org> Date: Mon, 25 Oct 2021 15:09:12 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Oct 2021 15:09:12 -0000 https://gcc.gnu.org/g:234815d4c38608eb1bff20f68d6dd4c233f07725 commit r12-4683-g234815d4c38608eb1bff20f68d6dd4c233f07725 Author: Piotr Trojanek Date: Mon Oct 11 14:09:42 2021 +0200 [Ada] Simplify iteration of record components when expanding equality gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): Fix style. (Element_To_Compare): Simplify loop. (Expand_Record_Equality): Adapt calls to Element_To_Compare. Diff: --- gcc/ada/exp_ch4.adb | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 8dcfa85e756..3dd0cc4f1af 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -2583,7 +2583,7 @@ package body Exp_Ch4 is return Make_Function_Call (Loc, - Name => New_Occurrence_Of (Eq_Op, Loc), + Name => New_Occurrence_Of (Eq_Op, Loc), Parameter_Associations => New_List (Unchecked_Convert_To (Etype (First_Formal (Eq_Op)), Lhs), @@ -2606,7 +2606,7 @@ package body Exp_Ch4 is begin return Make_Function_Call (Loc, - Name => New_Occurrence_Of (Eq_Op, Loc), + Name => New_Occurrence_Of (Eq_Op, Loc), Parameter_Associations => New_List ( OK_Convert_To (T, Lhs), OK_Convert_To (T, Rhs))); @@ -13116,41 +13116,35 @@ package body Exp_Ch4 is ------------------------ function Element_To_Compare (C : Entity_Id) return Entity_Id is - Comp : Entity_Id; + Comp : Entity_Id := C; begin - Comp := C; - loop - -- Exit loop when the next element to be compared is found, or - -- there is no more such element. - - exit when No (Comp); - - exit when Ekind (Comp) in E_Discriminant | E_Component - and then not ( + while Present (Comp) loop + -- Skip inherited components - -- Skip inherited components + -- Note: for a tagged type, we always generate the "=" primitive + -- for the base type (not on the first subtype), so the test for + -- Comp /= Original_Record_Component (Comp) is True for inherited + -- components only. - -- Note: for a tagged type, we always generate the "=" primitive - -- for the base type (not on the first subtype), so the test for - -- Comp /= Original_Record_Component (Comp) is True for - -- inherited components only. - - (Is_Tagged_Type (Typ) + if (Is_Tagged_Type (Typ) and then Comp /= Original_Record_Component (Comp)) - -- Skip _Tag + -- Skip _Tag or else Chars (Comp) = Name_uTag - -- Skip interface elements (secondary tags???) - - or else Is_Interface (Etype (Comp))); + -- Skip interface elements (secondary tags???) - Next_Entity (Comp); + or else Is_Interface (Etype (Comp)) + then + Next_Component_Or_Discriminant (Comp); + else + return Comp; + end if; end loop; - return Comp; + return Empty; end Element_To_Compare; -- Start of processing for Expand_Record_Equality @@ -13166,7 +13160,7 @@ package body Exp_Ch4 is -- and then Lhs.Cmpn = Rhs.Cmpn Result := New_Occurrence_Of (Standard_True, Loc); - C := Element_To_Compare (First_Entity (Typ)); + C := Element_To_Compare (First_Component_Or_Discriminant (Typ)); while Present (C) loop declare New_Lhs : Node_Id; @@ -13224,7 +13218,7 @@ package body Exp_Ch4 is end; First_Time := False; - C := Element_To_Compare (Next_Entity (C)); + C := Element_To_Compare (Next_Component_Or_Discriminant (C)); end loop; return Result;