From patchwork Thu Dec 2 16:28:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 48401 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A947D385841A for ; Thu, 2 Dec 2021 16:37:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A947D385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638463043; bh=Q3Uf71Od2+wiBpSaCaLSTckyPD0yGtgLZSDfW/IDx/E=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BDTi9wTacvGArB0F42DCTgko6jBn3Bwh/w1M5isa5sdaxbmwBB4jRLRrvVeC32+s7 nRu+PjH+Rrln7DD2nSCIiullQzpUY6OUgtbROPad5UdqgU6CQrO0R7MYrrHXMX7Cfk VTHH+psSjG1s7dIdRuIEHNucBvO/AyCgBtOXxz34= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 24890385BF99 for ; Thu, 2 Dec 2021 16:28:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 24890385BF99 Received: by mail-wr1-x42b.google.com with SMTP id o13so60674280wrs.12 for ; Thu, 02 Dec 2021 08:28:47 -0800 (PST) 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=Q3Uf71Od2+wiBpSaCaLSTckyPD0yGtgLZSDfW/IDx/E=; b=iECNxL+wOiodvJokr52gxYAd2JPUqKHTh3RzieCIGWvvYMprfMe9vgv7JetLVUBHax cJ7BWl/s5v2ig6UA8Azyqpzmav+Q2cy/RO2g2eyLILmE0AyZQPuApw+u0bN6nKvsLABx 9yGl6CnSZVgoUA6yaWLr7Px81VzpJIF64uXuS0B5U4QjJ9mTs0xdKvdyoyVD7g9rqJaf dxq5pTsVMwNn5Lz4uU9ac1xqmX4U+2VjwmyQA9b+GfybrQQMeRW8d7GrsSJf+5BIxv69 I4r6hkvk6VcRFGl31Db6YjGKF7Kwe1oOvuv7Ozuv6aeJg950jkf62tDJFwYxr9AAF43V iG2Q== X-Gm-Message-State: AOAM530Qwa2jPwsyjkndIOgBTb+EEU6Fj9KBOL1SSw5WlcLbP5roppdl Hi9+j8x2cIwd2sTa/aujAkH6WllAlZ8Y/Q== X-Google-Smtp-Source: ABdhPJz2geg1U9o5pARH5OalDGdQvL1+TqeIyqYoIutbGHwOg2B4bMUC+ycbencEDfnSXoa5kljAPQ== X-Received: by 2002:a5d:52c3:: with SMTP id r3mr15663411wrv.115.1638462526256; Thu, 02 Dec 2021 08:28:46 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id u15sm113050wmq.13.2021.12.02.08.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 08:28:45 -0800 (PST) Date: Thu, 2 Dec 2021 16:28:45 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Simplify iteration over record components Message-ID: <20211202162845.GA2157490@adacore.com> MIME-Version: 1.0 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-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Iterate over record components with First_Component/Next_Component and not with First_Entity/Next_Entity. Change in Sem_Warn unit is related to spurious warning on 'Initialized; other occurrences of the same pattern were found with grep. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * freeze.adb (Freeze_Entity): Replace First_Entity/Next_Entity with First_Component/Next_Component; remove condition with Ekind equal to E_Component. * sem_ch13.adb (Check_Record_Representation_Clause): Likewise for component-or-discriminant. * sem_util.adb (Is_Fully_Initialized_Type): Likewise; rename Ent to a more specific Comp. * sem_warn.adb (Check_References): Likewise. diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -6328,11 +6328,9 @@ package body Freeze is -- to the components of Rec. begin - Comp := First_Entity (E); + Comp := First_Component (E); while Present (Comp) loop - if Ekind (Comp) = E_Component - and then Has_Delayed_Aspects (Comp) - then + if Has_Delayed_Aspects (Comp) then if not Rec_Pushed then Push_Scope (E); Rec_Pushed := True; @@ -6348,7 +6346,7 @@ package body Freeze is Analyze_Aspects_At_Freeze_Point (Comp); end if; - Next_Entity (Comp); + Next_Component (Comp); end loop; -- Pop the scope if Rec scope has been pushed on the scope stack diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -12284,26 +12284,18 @@ package body Sem_Ch13 is -- Find maximum bit of any component of the parent type Parent_Last_Bit := UI_From_Int (System_Address_Size - 1); - Pcomp := First_Entity (Tagged_Parent); + Pcomp := First_Component_Or_Discriminant (Tagged_Parent); while Present (Pcomp) loop - if Ekind (Pcomp) in E_Discriminant | E_Component then - if Present (Component_Bit_Offset (Pcomp)) - and then Known_Static_Esize (Pcomp) - then - Parent_Last_Bit := - UI_Max - (Parent_Last_Bit, - Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); - end if; - else - - -- Skip anonymous types generated for constrained array - -- or record components. - - null; + if Present (Component_Bit_Offset (Pcomp)) + and then Known_Static_Esize (Pcomp) + then + Parent_Last_Bit := + UI_Max + (Parent_Last_Bit, + Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); end if; - Next_Entity (Pcomp); + Next_Component_Or_Discriminant (Pcomp); end loop; end if; end; diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -17803,15 +17803,14 @@ package body Sem_Util is -- Otherwise see if all record components are initialized declare - Ent : Entity_Id; + Comp : Entity_Id; begin - Ent := First_Entity (Typ); - while Present (Ent) loop - if Ekind (Ent) = E_Component - and then (No (Parent (Ent)) - or else No (Expression (Parent (Ent)))) - and then not Is_Fully_Initialized_Type (Etype (Ent)) + Comp := First_Component (Typ); + while Present (Comp) loop + if (No (Parent (Comp)) + or else No (Expression (Parent (Comp)))) + and then not Is_Fully_Initialized_Type (Etype (Comp)) -- Special VM case for tag components, which need to be -- defined in this case, but are never initialized as VMs @@ -17819,12 +17818,12 @@ package body Sem_Util is -- uninitialized case. Note that this applies both to the -- uTag entry and the main vtable pointer (CPP_Class case). - and then (Tagged_Type_Expansion or else not Is_Tag (Ent)) + and then (Tagged_Type_Expansion or else not Is_Tag (Comp)) then return False; end if; - Next_Entity (Ent); + Next_Component (Comp); end loop; end; diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -1548,18 +1548,17 @@ package body Sem_Warn is Comp : Entity_Id; begin - Comp := First_Entity (E1T); + Comp := First_Component (E1T); while Present (Comp) loop - if Ekind (Comp) = E_Component - and then Nkind (Parent (Comp)) = - N_Component_Declaration + if Nkind (Parent (Comp)) = + N_Component_Declaration and then No (Expression (Parent (Comp))) then Error_Msg_Node_2 := Comp; exit; end if; - Next_Entity (Comp); + Next_Component (Comp); end loop; end; end if;