From patchwork Thu Jan 6 17:13:12 2022 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: 49655 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 6435A3858001 for ; Thu, 6 Jan 2022 17:34:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6435A3858001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641490450; bh=/RE0Y59+C6bhXuiqlWsKzx1NadOJUSNYA71TCHUO5jg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=LnsL5AYRff8gvanL2i8bQCBh0cVRWV5g76FDWdRnfKvlilxRKcoAUofBe+YO1OaHZ L7/AuejgEDdNqQvmj9kMdtE/qWegj3tUz61NDigQQnNaBamjpOFqgVVKzyiHIvg2u4 5X6uPNfcEY5QPDpFmZA414kZ3hNeTOEYvoslF52Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 28683385800C for ; Thu, 6 Jan 2022 17:13:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 28683385800C Received: by mail-wr1-x430.google.com with SMTP id s1so6115765wra.6 for ; Thu, 06 Jan 2022 09:13:14 -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=/RE0Y59+C6bhXuiqlWsKzx1NadOJUSNYA71TCHUO5jg=; b=kosnoqDPkap+IqObcL1MvrozTYyhOonTozWmLuEUBYgDKhsBcdtWCAMlNtTnVe+2Gr MO6TJd+aGiBfkToNr/o3h7oo28j6DAFHkITc71icMSQBEFj+/+af+g9KDp4uk9gr1uIT +omRv/I/1cseFCStkz8hFKVpVG4QwQQbr8Lj6fQGSTU66WP3rgFuJEvHyvutLYhwXaBV skndrVTzC+aq9axCV0iDc//wRHj93FlLv3cGB6qEu1H8BA7uxHiW2mhTMexmLAhrOkGm EfZ4yMu46n3wtRZBigTQBmQ/f7I0wEvS0qNR1f7K7jezRbOAewtPaoGW56kox0QdTdN6 eWOQ== X-Gm-Message-State: AOAM533Qkdf1Vq8BVtJhhVccJlRJ3qxSYXJfOfmqUkGFi6TZUackYnfi LbKPtU73La8XeZiSyajUD1HTdebePBtcLA== X-Google-Smtp-Source: ABdhPJx0H9bL164Hzhds4fKFQINblz8f61Ik5FX4Y58hjuEMQ4fGkSpF4ByWmnHh93QkYzqNxtaNLg== X-Received: by 2002:a05:6000:1563:: with SMTP id 3mr51905546wrz.372.1641489193240; Thu, 06 Jan 2022 09:13:13 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id c23sm1422997wmr.9.2022.01.06.09.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 09:13:12 -0800 (PST) Date: Thu, 6 Jan 2022 17:13:12 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Remove unnecessary guards for non-empty lists Message-ID: <20220106171312.GA2921754@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" All node lists can be safely iterated with First/Present/Next. There is no need for explicit guard against empty lists. Code cleanup. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * errout.adb (Remove_Warning_Messages): Remove unnecessary guard. * exp_util.adb (Kill_Dead_Code): Likewise. * par_sco.adb (Traverse_Declarations_Or_Statements): Likewise. * sem_ch3.adb (Build_Derived_Record_Type): Likewise. * sem_ch4.adb (Traverse_Interfaces): Likewise. * sem_eval.adb (Traverse_Interfaces): Likewise. * sem_util.adb (Collect_Interfaces): Likewise. (Has_Non_Null_Statements, Side_Effect_Free_Statements): Likewise; turn into WHILE loops, for consistency. diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -3378,13 +3378,11 @@ package body Errout is procedure Remove_Warning_Messages (L : List_Id) is Stat : Node_Id; begin - if Is_Non_Empty_List (L) then - Stat := First (L); - while Present (Stat) loop - Remove_Warning_Messages (Stat); - Next (Stat); - end loop; - end if; + Stat := First (L); + while Present (Stat) loop + Remove_Warning_Messages (Stat); + Next (Stat); + end loop; end Remove_Warning_Messages; -------------------- diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -9495,14 +9495,12 @@ package body Exp_Util is begin W := Warn; - if Is_Non_Empty_List (L) then - N := First (L); - while Present (N) loop - Kill_Dead_Code (N, W); - W := False; - Next (N); - end loop; - end if; + N := First (L); + while Present (N) loop + Kill_Dead_Code (N, W); + W := False; + Next (N); + end loop; end Kill_Dead_Code; ----------------------------- diff --git a/gcc/ada/par_sco.adb b/gcc/ada/par_sco.adb --- a/gcc/ada/par_sco.adb +++ b/gcc/ada/par_sco.adb @@ -2417,21 +2417,18 @@ package body Par_SCO is -- Loop through statements or declarations - if Is_Non_Empty_List (L) then - N := First (L); - while Present (N) loop + N := First (L); + while Present (N) loop - -- Note: For separate bodies, we see the tree after Par.Labl has - -- introduced implicit labels, so we need to ignore those nodes. + -- Note: For separate bodies, we see the tree after Par.Labl has + -- introduced implicit labels, so we need to ignore those nodes. - if Nkind (N) /= N_Implicit_Label_Declaration then - Traverse_One (N); - end if; - - Next (N); - end loop; + if Nkind (N) /= N_Implicit_Label_Declaration then + Traverse_One (N); + end if; - end if; + Next (N); + end loop; -- End sequence of statements and flush deferred decisions diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -9351,13 +9351,11 @@ package body Sem_Ch3 is declare Iface : Node_Id; begin - if Is_Non_Empty_List (Interface_List (Type_Def)) then - Iface := First (Interface_List (Type_Def)); - while Present (Iface) loop - Freeze_Before (N, Etype (Iface)); - Next (Iface); - end loop; - end if; + Iface := First (Interface_List (Type_Def)); + while Present (Iface) loop + Freeze_Before (N, Etype (Iface)); + Next (Iface); + end loop; end; end if; diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -9597,31 +9597,29 @@ package body Sem_Ch4 is begin Error := False; - if Is_Non_Empty_List (Intface_List) then - Intface := First (Intface_List); - while Present (Intface) loop + Intface := First (Intface_List); + while Present (Intface) loop - -- Look for acceptable class-wide homonyms associated with - -- the interface. + -- Look for acceptable class-wide homonyms associated with the + -- interface. - Traverse_Homonyms (Etype (Intface), Error); + Traverse_Homonyms (Etype (Intface), Error); - if Error then - return; - end if; + if Error then + return; + end if; - -- Continue the search by looking at each of the interface's - -- associated interface ancestors. + -- Continue the search by looking at each of the interface's + -- associated interface ancestors. - Traverse_Interfaces (Etype (Intface), Error); + Traverse_Interfaces (Etype (Intface), Error); - if Error then - return; - end if; + if Error then + return; + end if; - Next (Intface); - end loop; - end if; + Next (Intface); + end loop; end Traverse_Interfaces; -- Start of processing for Try_Class_Wide_Operation diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -7479,13 +7479,11 @@ package body Sem_Eval is procedure Why_Not_Static_List (L : List_Id) is N : Node_Id; begin - if Is_Non_Empty_List (L) then - N := First (L); - while Present (N) loop - Why_Not_Static (N); - Next (N); - end loop; - end if; + N := First (L); + while Present (N) loop + Why_Not_Static (N); + Next (N); + end loop; end Why_Not_Static_List; -- Start of processing for Why_Not_Static 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 @@ -6046,31 +6046,29 @@ package body Sem_Util is -- Traverse the graph of ancestor interfaces - if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then - Id := First (Abstract_Interface_List (Full_T)); - while Present (Id) loop - Iface := Etype (Id); - - -- Protect against wrong uses. For example: - -- type I is interface; - -- type O is tagged null record; - -- type Wrong is new I and O with null record; -- ERROR - - if Is_Interface (Iface) then - if Exclude_Parents - and then Etype (T) /= T - and then Interface_Present_In_Ancestor (Etype (T), Iface) - then - null; - else - Collect (Iface); - Append_Unique_Elmt (Iface, Ifaces_List); - end if; + Id := First (Abstract_Interface_List (Full_T)); + while Present (Id) loop + Iface := Etype (Id); + + -- Protect against wrong uses. For example: + -- type I is interface; + -- type O is tagged null record; + -- type Wrong is new I and O with null record; -- ERROR + + if Is_Interface (Iface) then + if Exclude_Parents + and then Etype (T) /= T + and then Interface_Present_In_Ancestor (Etype (T), Iface) + then + null; + else + Collect (Iface); + Append_Unique_Elmt (Iface, Ifaces_List); end if; + end if; - Next (Id); - end loop; - end if; + Next (Id); + end loop; end Collect; -- Start of processing for Collect_Interfaces @@ -13024,18 +13022,15 @@ package body Sem_Util is Node : Node_Id; begin - if Is_Non_Empty_List (L) then - Node := First (L); + Node := First (L); - loop - if Nkind (Node) not in N_Null_Statement | N_Call_Marker then - return True; - end if; + while Present (Node) loop + if Nkind (Node) not in N_Null_Statement | N_Call_Marker then + return True; + end if; - Next (Node); - exit when Node = Empty; - end loop; - end if; + Next (Node); + end loop; return False; end Has_Non_Null_Statements; @@ -13094,28 +13089,26 @@ package body Sem_Util is Node : Node_Id; begin - if Is_Non_Empty_List (L) then - Node := First (L); + Node := First (L); - loop - case Nkind (Node) is - when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error => - null; - when N_Object_Declaration => - if Present (Expression (Node)) - and then not Side_Effect_Free (Expression (Node)) - then - return False; - end if; + while Present (Node) loop + case Nkind (Node) is + when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error => + null; - when others => + when N_Object_Declaration => + if Present (Expression (Node)) + and then not Side_Effect_Free (Expression (Node)) + then return False; - end case; + end if; - Next (Node); - exit when Node = Empty; - end loop; - end if; + when others => + return False; + end case; + + Next (Node); + end loop; return True; end Side_Effect_Free_Statements;