From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 691A73858435 for ; Mon, 25 Oct 2021 15:09:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 691A73858435 Received: by mail-lj1-x22f.google.com with SMTP id d13so9071512ljg.0 for ; Mon, 25 Oct 2021 08:09:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=Gu4g78pWNgMkIaWzRTCF+ElN2jrdprOs3oOQG3nr9bc=; b=Z2KBWYr0ZD89mog1HsnKkW3aPCoIZFQAF8GQjWp+Jyq1AgMci55hienOEls29vTtdZ GkeqQJYEvVSFRX5FU0r5ryyaQPzxoxjLX9AZYgGrYdUMPQxPx++32ic+buUIT16U4l+L oOLMG/reEUv5a1f4a38ReKNa7gGXdp0e9zAeiihpSXzGgjWfdD3QAeepKrfO+Jj2VMa1 sDJH6hJRIOs0kZ13Kbc3nOUlTNZdlPan3Lxo17h0VRBwgj6u8SEC7XsiUAiGhe6Vb2DO /cyU3RRXQ6j1Nqu8KM6TrOlJKKaKePx5tpClVLUK/0sSPZdhUU89skRqHgFkIcqzjXk3 VugQ== X-Gm-Message-State: AOAM5337MQjI7XSFPB355qiryj+cxEuaQu3AT4pe0hQkd+pC6gRM2tE/ IrdzxL1YPejheKkyGBCp1Urm6gdZAV05p/pU X-Google-Smtp-Source: ABdhPJwHXdQu/9ilXXHDsAkUH7wte3pRbbYzfJJqU3EcEHOztaxY0oWCNh5X4P0TDm1M78/2UVqiSw== X-Received: by 2002:a2e:810b:: with SMTP id d11mr19387827ljg.363.1635174570288; Mon, 25 Oct 2021 08:09:30 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id a12sm324252lff.236.2021.10.25.08.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 08:09:29 -0700 (PDT) Date: Mon, 25 Oct 2021 15:09:28 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Simplify iteration of record components when expanding equality Message-ID: <20211025150928.GA346759@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="y0ulUmNC+osPPQO6" Content-Disposition: inline X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Oct 2021 15:09:34 -0000 --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Replace a confusing loop with two exit staments by a straightforward while loop with an explicit condition. Also, explicitly iterate over discriminants and components, not over entities. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): Fix style. (Element_To_Compare): Simplify loop. (Expand_Record_Equality): Adapt calls to Element_To_Compare. --y0ulUmNC+osPPQO6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb --- 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; --y0ulUmNC+osPPQO6--