From patchwork Tue Jan 11 13:32:37 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: 49865 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 3AA6338A940C for ; Tue, 11 Jan 2022 14:06:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AA6338A940C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641909976; bh=UraGcZizm0mi+l3Xc0AO6gmi2UAKNxGuQG3FgVCaz60=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=eAOfBG8ltYepAxwlNbVCxwbsv3yNc6mneMQpOOjRoAKAf6PqgCzedrQ97NUaLdRzZ SCMfyzhbcuIHvyLXHbfOQlHX31+BQEf1ZW9o4A7XtUwrv3kPy239z+6nXaqVtTbSPS wOU7pOI/KaA6F9dh4qPETQ8HmnV1KoOwh00rDyKE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id C5D5538A9439 for ; Tue, 11 Jan 2022 13:32:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C5D5538A9439 Received: by mail-wm1-x331.google.com with SMTP id 25-20020a05600c231900b003497473a9c4so1440442wmo.5 for ; Tue, 11 Jan 2022 05:32:39 -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=UraGcZizm0mi+l3Xc0AO6gmi2UAKNxGuQG3FgVCaz60=; b=c9iwmCO7TutAqBJs8lTZq8PpKAMr3OnXaQo8oCSce7aTOBNKWyR2WmJGE6fy/hA4Go KqHWtZkS/cYLSMBeOqdNy8cDxhY7q4lbF+lc3AN8Z6sixSG8PAuggv1KeDm/jTEXV3xi /reXvaiCOCe33P7OP+xXZbRUg8qw8U3cQmgiXm1nPHKnrIegR588WOSXd8BsvBPFTIFx bkef6QzC4I2HI4P5U0JEJOoPOFOw5OYDVH0hr5O7ZbpTc9JqPfJ4ucOXvYtNSJv/Tk/4 XgJ4tGGtux72YuTOFAUutxkyVfk0pER1/QaLPsCI67LeiCFz18YydVpOJ76HA9clUrCV Av0A== X-Gm-Message-State: AOAM532ThTyyIsPRdn6dfUUjbKz+YDgfBTSs1hSN9adX5YZV+qBF91j1 Lo1vFGWnaF6AWpzlz8zkMVfIyvJkRo1YYw== X-Google-Smtp-Source: ABdhPJyQAhWKKAw8O66SUPPvjMdDoLCK+otZFhu0bEecNgJ/r5It2Z4tgxJ58M4dc6UNJUkk3nhoPw== X-Received: by 2002:a05:600c:21c6:: with SMTP id x6mr2513937wmj.135.1641907958909; Tue, 11 Jan 2022 05:32:38 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id o13sm9808198wrc.111.2022.01.11.05.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:32:38 -0800 (PST) Date: Tue, 11 Jan 2022 13:32:37 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Avoid redundant checks for empty lists Message-ID: <20220111133237.GA748963@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 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" Simplify "No (L) or else Is_Empty_List (L)" into "Is_Empty_List (L)", since Is_Empty_List can be called on No_List and returns True. Code cleanup; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (Expand_N_Expression_With_Actions): Avoid redundant check. * exp_ch5.adb (Expand_N_If_Statement): Likewise. * exp_ch7.adb (Process_Declarations): Likewise. * sem_elab.adb (Freeze_Node_Location): Likewise. * exp_util.adb (Insert_Actions): Likewise. (Is_OK_PF_Pragma): Likewise. (Requires_Cleanup_Actions): Remove early exit; ordinary processing path will similarly do nothing. 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 @@ -5697,7 +5697,7 @@ package body Exp_Ch4 is -- Do not evaluate the expression when there are no actions because the -- expression_with_actions node will be replaced by the expression. - elsif No (Acts) or else Is_Empty_List (Acts) then + elsif Is_Empty_List (Acts) then null; -- Force the evaluation of the expression by capturing its value in a diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -4475,9 +4475,7 @@ package body Exp_Ch5 is -- entire if statement by the sequence of else statements. if No (Elsif_Parts (N)) then - if No (Else_Statements (N)) - or else Is_Empty_List (Else_Statements (N)) - then + if Is_Empty_List (Else_Statements (N)) then Rewrite (N, Make_Null_Statement (Sloc (N))); else diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -2249,7 +2249,7 @@ package body Exp_Ch7 is -- Start of processing for Process_Declarations begin - if No (Decls) or else Is_Empty_List (Decls) then + if Is_Empty_List (Decls) then return; end if; 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 @@ -7172,7 +7172,7 @@ package body Exp_Util is Wrapped_Node : Node_Id := Empty; begin - if No (Ins_Actions) or else Is_Empty_List (Ins_Actions) then + if Is_Empty_List (Ins_Actions) then return; end if; @@ -9963,7 +9963,7 @@ package body Exp_Util is -- Nothing to do when the pragma lacks arguments, in which case it -- is illegal. - elsif No (Args) or else Is_Empty_List (Args) then + elsif Is_Empty_List (Args) then return False; end if; @@ -12674,10 +12674,6 @@ package body Exp_Util is Typ : Entity_Id; begin - if No (L) or else Is_Empty_List (L) then - return False; - end if; - Decl := First (L); while Present (Decl) loop diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb --- a/gcc/ada/sem_elab.adb +++ b/gcc/ada/sem_elab.adb @@ -15382,7 +15382,7 @@ package body Sem_Elab is elsif Present (Vis_Decls) and then List_Containing (FNode) = Vis_Decls - and then (No (Prv_Decls) or else Is_Empty_List (Prv_Decls)) + and then Is_Empty_List (Prv_Decls) then null;