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: 99349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp291903vqr; Fri, 26 May 2023 00:44:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IV+vCuaErVnO/pQDUA6ROi0vJLZkcujJrnoln5La109SKiNXhVB2HjsXLN5l5PG1KqwIP X-Received: by 2002:a17:907:80c:b0:94a:9f9a:b3c4 with SMTP id wv12-20020a170907080c00b0094a9f9ab3c4mr1068913ejb.49.1685087068250; Fri, 26 May 2023 00:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685087068; cv=none; d=google.com; s=arc-20160816; b=uFg7kEsnKCT7fUszWBaRTTVlRI9Abx5XDDQxYMHeS4dPLnq6PiMs/C0h6eRxrA4z3j 6qGajP8pt8rK6NuPrm1R28VyZv1uH9IxwE6PfKHYBTG1RRx4hvqRGC0eiXf8aN1VUUnG xCeiEI0k2ED1GoL9c9EShNA8jM/2teKn5UI1r44QhTwf3Nwu79HXCErJciRaiyGcWa8x xhyfOY166ng1X9VTARbFIool1lRMc2Lou0lp2krtUhCg+fu2fcrP8+TJk176nOE86pDB 6yat/eoE0cDZ8xw+LU+ePlmlS31lltujxvO8vfbaFAGZjswC84uNotTsllQHKDmIoZAH uThw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=5axnlIOxnCeCN2U87yYrFtb/KX0dtIF7tzwzNC4J1iQ=; b=e5pVRMARuV3DXkqSRJtjfCjgsm+NQC3skb9kvI9lTJParSkGjfIHzZ/HN89gwi4Smk TtQTXZ1yMa+4AnHdvKxmWzfHKDlzNuAmPQBGef8BxEezB09MI2BSGvHLpDv1v1l0Xwmz qgk9N66unMzEELltyp8D15wMvDAceKK/WrVu7vDHMQaWnDArFfPDTMh1XtVwjrANgRPo hA70WksrgVecKlwQd0hcGV/LmxuePk9UCDVNEI0NfZyaHMCFkcA3fL9she+yYlTyNRki /irLE99z4+HoyUDtSExLV2y1xp3MfbWIslefFMDJGFKahEESJgisLc5GdjwbrXizmaTB vJ+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HSYPtW35; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gv24-20020a170906f11800b0096f79bb335csi45496ejb.837.2023.05.26.00.44.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:44:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HSYPtW35; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35A5B3947C3A for ; Fri, 26 May 2023 07:39:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35A5B3947C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685086793; 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=HSYPtW35IePl+atw7NsvjK7zPXXLzePX4YswcRol0GVSsMpjIr1l+ZDl4ew1776vh F9f4MoIZ4P+9VS1Xmet+9g/6JkvSdJ/PArNn+ZNAzTcrvnL0aYFLEuxSFnJPMbFhqA qTtHiY9u0/VtjjRCvQWlMZDt7458W1Qpx0RQRjo8= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766941857630233833?= X-GMAIL-MSGID: =?utf-8?q?1766941857630233833?= 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