From patchwork Fri May 26 07:36:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 70127 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 1EE553940CF7 for ; Fri, 26 May 2023 07:39:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EE553940CF7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685086774; bh=5axnlIOxnCeCN2U87yYrFtb/KX0dtIF7tzwzNC4J1iQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=YRGjKFpUAtY16cS0JuCuL5Mj/7cGKjBLW4AD2Cr6ncJLiLt2VMNbzqlA8j1yvcab6 2J9X3mf2dcZaOoZ4Vozyzu9GHNpwxoQonJTWQo5dRTPRhQ5jzdQWYIkojDofNGDNHg I4Eg0qEhcDGsFgHJOnZvJuoGCvfKqjPAdG2quX7c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 81928385771C for ; Fri, 26 May 2023 07:36:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81928385771C Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f6ef9a928fso151045e9.3 for ; Fri, 26 May 2023 00:36:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685086574; x=1687678574; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5axnlIOxnCeCN2U87yYrFtb/KX0dtIF7tzwzNC4J1iQ=; b=WHgLiPjVIUp+YODccUAWsI5jEnoQ/zLnl+ukp85DtS6O088nJTY3IlHYswuzfQcvez b1/rkcCGSANdf/MB5RmlE0T1iqGJ9OhNnYAQrAudytWG50OCjs2RVl6VZVJy/EO1BjyP 9sffAym7qlBTB002kHx81L6+Ko0FUoemqXxPUcjZJMvD70ZSi8EnOszjj+RCQVSwzpCN hR7O28rPeK2du3vwpTEBmLUhMQwDuWNIUD/96w7920icbD1j+PW9wd5t5c/VTGZXEVl+ zo2xWLzKpVzhN0H2MaM5s3bHv6kVqqaOLm4WVkTVIjBW5+vdprZ2YjNuwCm8Ul1RLAxH gHLQ== X-Gm-Message-State: AC+VfDywu+WF1ZWnyWA17fM0X/CB9mTxZGDADe2xn3mAYZUB11b/cGgE JAwFRXodj1JOlhF92Hh0g4Y6fdM7voq0xrG1s+O7zw== X-Google-Smtp-Source: ACHHUZ4Xj81pMEhJ71EN2r2078tdbB552aUVN/3XiwwBHNjQ03tnD5HlawJUzfNGzvLX7J7kEhRbZw== X-Received: by 2002:a7b:ce19:0:b0:3f4:2267:10cf with SMTP id m25-20020a7bce19000000b003f4226710cfmr886175wmc.32.1685086574088; Fri, 26 May 2023 00:36:14 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:777b:eef4:6f79:f26f]) by smtp.gmail.com with ESMTPSA id z10-20020a7bc7ca000000b003f602e2b653sm7922122wmk.28.2023.05.26.00.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:36:13 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Remove redundant protection against empty lists Date: Fri, 26 May 2023 09:36:12 +0200 Message-Id: <20230526073612.2068697-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Piotr Trojanek Calls to Length on No_List intentionally return 0, so explicit guards against No_List are unnecessary. Code cleanup; semantics is unaffected. gcc/ada/ * sem_ch13.adb (Check_Component_List): Local variable Compl is now a constant; a nested block is no longer needed. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch13.adb | 238 +++++++++++++++++++++---------------------- 1 file changed, 116 insertions(+), 122 deletions(-) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 593e6f8c169..b13af26b561 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -11978,163 +11978,157 @@ package body Sem_Ch13 is Sbit : Uint; Abit : out Uint) is - Compl : Integer; + Compl : constant Natural := + Natural (List_Length (Component_Items (CL)) + List_Length (DS)); - begin - Compl := Integer (List_Length (Component_Items (CL))); - - if DS /= No_List then - Compl := Compl + Integer (List_Length (DS)); - end if; - - declare - Comps : array (Natural range 0 .. Compl) of Entity_Id; - -- Gather components (zero entry is for sort routine) + Comps : array (Natural range 0 .. Compl) of Entity_Id; + -- Gather components (zero entry is for sort routine) - Ncomps : Natural := 0; - -- Number of entries stored in Comps (starting at Comps (1)) + Ncomps : Natural := 0; + -- Number of entries stored in Comps (starting at Comps (1)) - Citem : Node_Id; - -- One component item or discriminant specification + Citem : Node_Id; + -- One component item or discriminant specification - Nbit : Uint; - -- Starting bit for next component + Nbit : Uint; + -- Starting bit for next component - CEnt : Entity_Id; - -- Component entity + CEnt : Entity_Id; + -- Component entity - Variant : Node_Id; - -- One variant + Variant : Node_Id; + -- One variant - function Lt (Op1, Op2 : Natural) return Boolean; - -- Compare routine for Sort + function Lt (Op1, Op2 : Natural) return Boolean; + -- Compare routine for Sort - procedure Move (From : Natural; To : Natural); - -- Move routine for Sort + procedure Move (From : Natural; To : Natural); + -- Move routine for Sort - package Sorting is new GNAT.Heap_Sort_G (Move, Lt); + package Sorting is new GNAT.Heap_Sort_G (Move, Lt); - -------- - -- Lt -- - -------- + -------- + -- Lt -- + -------- - function Lt (Op1, Op2 : Natural) return Boolean is - K1 : constant Boolean := - Known_Component_Bit_Offset (Comps (Op1)); - K2 : constant Boolean := - Known_Component_Bit_Offset (Comps (Op2)); - -- Record representation clauses can be incomplete, so the - -- Component_Bit_Offsets can be unknown. - begin - if K1 then - if K2 then - return Component_Bit_Offset (Comps (Op1)) - < Component_Bit_Offset (Comps (Op2)); - else - return True; - end if; + function Lt (Op1, Op2 : Natural) return Boolean is + K1 : constant Boolean := + Known_Component_Bit_Offset (Comps (Op1)); + K2 : constant Boolean := + Known_Component_Bit_Offset (Comps (Op2)); + -- Record representation clauses can be incomplete, so the + -- Component_Bit_Offsets can be unknown. + begin + if K1 then + if K2 then + return Component_Bit_Offset (Comps (Op1)) + < Component_Bit_Offset (Comps (Op2)); else - return K2; + return True; end if; - end Lt; + else + return K2; + end if; + end Lt; - ---------- - -- Move -- - ---------- - - procedure Move (From : Natural; To : Natural) is - begin - Comps (To) := Comps (From); - end Move; + ---------- + -- Move -- + ---------- + procedure Move (From : Natural; To : Natural) is begin - -- Gather discriminants into Comp + Comps (To) := Comps (From); + end Move; - Citem := First (DS); - while Present (Citem) loop - if Nkind (Citem) = N_Discriminant_Specification then - declare - Ent : constant Entity_Id := - Defining_Identifier (Citem); - begin - if Ekind (Ent) = E_Discriminant then - Ncomps := Ncomps + 1; - Comps (Ncomps) := Ent; - end if; - end; - end if; + -- Start of processing for Check_Component_List - Next (Citem); - end loop; + begin + -- Gather discriminants into Comp - -- Gather component entities into Comp + Citem := First (DS); + while Present (Citem) loop + if Nkind (Citem) = N_Discriminant_Specification then + declare + Ent : constant Entity_Id := + Defining_Identifier (Citem); + begin + if Ekind (Ent) = E_Discriminant then + Ncomps := Ncomps + 1; + Comps (Ncomps) := Ent; + end if; + end; + end if; - Citem := First (Component_Items (CL)); - while Present (Citem) loop - if Nkind (Citem) = N_Component_Declaration then - Ncomps := Ncomps + 1; - Comps (Ncomps) := Defining_Identifier (Citem); - end if; + Next (Citem); + end loop; - Next (Citem); - end loop; + -- Gather component entities into Comp - -- Now sort the component entities based on the first bit. - -- Note we already know there are no overlapping components. + Citem := First (Component_Items (CL)); + while Present (Citem) loop + if Nkind (Citem) = N_Component_Declaration then + Ncomps := Ncomps + 1; + Comps (Ncomps) := Defining_Identifier (Citem); + end if; - Sorting.Sort (Ncomps); + Next (Citem); + end loop; - -- Loop through entries checking for holes + -- Now sort the component entities based on the first bit. + -- Note we already know there are no overlapping components. - Nbit := Sbit; - for J in 1 .. Ncomps loop - CEnt := Comps (J); - pragma Annotate (CodePeer, Modified, CEnt); + Sorting.Sort (Ncomps); - declare - CBO : constant Uint := Component_Bit_Offset (CEnt); + -- Loop through entries checking for holes - begin - -- Skip components with unknown offsets + Nbit := Sbit; + for J in 1 .. Ncomps loop + CEnt := Comps (J); + pragma Annotate (CodePeer, Modified, CEnt); - if Present (CBO) and then CBO >= 0 then - Error_Msg_Uint_1 := CBO - Nbit; + declare + CBO : constant Uint := Component_Bit_Offset (CEnt); - if Warn and then Error_Msg_Uint_1 > 0 then - Error_Msg_NE - ("?.h?^-bit gap before component&", - Component_Name (Component_Clause (CEnt)), - CEnt); - end if; + begin + -- Skip components with unknown offsets + + if Present (CBO) and then CBO >= 0 then + Error_Msg_Uint_1 := CBO - Nbit; - Nbit := CBO + Esize (CEnt); + if Warn and then Error_Msg_Uint_1 > 0 then + Error_Msg_NE + ("?.h?^-bit gap before component&", + Component_Name (Component_Clause (CEnt)), + CEnt); end if; - end; - end loop; - -- Set Abit to just after the last nonvariant component + Nbit := CBO + Esize (CEnt); + end if; + end; + end loop; + + -- Set Abit to just after the last nonvariant component - Abit := Nbit; + Abit := Nbit; - -- Process variant parts recursively if present. Set Abit to - -- the maximum for all variant parts. + -- Process variant parts recursively if present. Set Abit to the + -- maximum for all variant parts. - if Present (Variant_Part (CL)) then - declare - Var_Start : constant Uint := Nbit; - begin - Variant := First (Variants (Variant_Part (CL))); - while Present (Variant) loop - Check_Component_List - (No_List, Component_List (Variant), Var_Start, Nbit); - Next (Variant); - if Nbit > Abit then - Abit := Nbit; - end if; - end loop; - end; - end if; - end; + if Present (Variant_Part (CL)) then + declare + Var_Start : constant Uint := Nbit; + begin + Variant := First (Variants (Variant_Part (CL))); + while Present (Variant) loop + Check_Component_List + (No_List, Component_List (Variant), Var_Start, Nbit); + Next (Variant); + if Nbit > Abit then + Abit := Nbit; + end if; + end loop; + end; + end if; end Check_Component_List; -- Local variables