From patchwork Tue Jul 5 08:29:49 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: 1652346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=t2FI+1Fh; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LcbXn2DZ0z9s1l for ; Tue, 5 Jul 2022 18:33:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C6CE3839428 for ; Tue, 5 Jul 2022 08:33:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C6CE3839428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657009991; bh=BMxjeSXiIPg/m4LgGRS6fxgxnek7ztLmDUJRrc8RTZA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=t2FI+1Fh1hlWDcFWMKpnciOAm+qA3DiNWDoZ0nto7Q1CxuxAq4rLmQBXTUJOFf+ZD UuFNS1zz63ABbwzU8s4txxrtQtP1zYg4elajv+xTHBjV2diPReLmztNeUpzhpTHySV UIMo1WM1qjU8rWM1SCIbtMkmYyFie9KkpNTZAaOg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 01274385742A for ; Tue, 5 Jul 2022 08:29:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01274385742A Received: by mail-wr1-x42c.google.com with SMTP id b26so16457262wrc.2 for ; Tue, 05 Jul 2022 01:29:50 -0700 (PDT) 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=BMxjeSXiIPg/m4LgGRS6fxgxnek7ztLmDUJRrc8RTZA=; b=oqmi7wDyhwac9xm1qWzrigy+T7ZpkwKV+tg4Si0FIH0U7cOSvZ+UFpdb3qIvsHK7Tc focXH/Ou9UvFkCk3iF8q3QhtnY1SmtOZBxQbcd21taz8qINpVWjuOk8LJo7rkTVWthgN ywpYztR1E33T02VntERT4eeJj1j5Xj9AR6YooTLEQiz2tkdCSgY5sk/ys8+t60gNR+Sq ht28WJP9kScgH2oLCi8OXSS/5MXm6MHRSYaPOYouqTWUaOWFplPtY+jgIP9e8GMfyojW ToLsnFDd5SjFUbgVFO8EyMJW7qXF33+4IWkmBWY015Lq8OS8AHAMwhG8KmgZKis7WZgp flEA== X-Gm-Message-State: AJIora/1e5KjWEaNDWG/CVcbPROiirHKGPH6Cd9BHD6UoT08zobzeQhh tqz01Iv+QZInQ6aok1yI5MNaltdPa622UQ== X-Google-Smtp-Source: AGRyM1vinnpB0CZG8MTX63qmwNtIxCNQpkhVoxhWrIMBLLiJHmUuYbcm0zSg5fvfodPWx7J8dhcVGw== X-Received: by 2002:a05:6000:1367:b0:21d:75cd:5ae8 with SMTP id q7-20020a056000136700b0021d75cd5ae8mr994346wrz.282.1657009790581; Tue, 05 Jul 2022 01:29:50 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id n7-20020a5d67c7000000b0021b9e8d4c22sm32265359wrw.61.2022.07.05.01.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jul 2022 01:29:50 -0700 (PDT) Date: Tue, 5 Jul 2022 08:29:49 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Remove unnecessary dead code after calls to nonreturning procedures Message-ID: <20220705082949.GA3180148@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.3 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: 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" A new warning about unreachable code that follows calls to procedures with No_Return would flag some dead defensive code. Comments next to this code suggest that it was added to please some ancient version of the compiler, but recent releases of GNAT do not require such a code. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gnatls.adb (Corresponding_Sdep_Entry): Remove dead return statement in defensive path; there is another return statement for a normal execution of this routine, so rule Ada RM 6.5(5), which requires function to have at least one return statement is still satisfied. (Gnatls): Remove dead, call to nonreturning Exit_Program after Output_License_Information which itself does not return. * libgnat/a-exstat.adb (Bad_EO): Remove raise statement that was meant to please some ancient version of GNAT. * libgnat/g-awk.adb (Raise_With_Info): Likewise. * sem_attr.adb (Check_Reference): Remove dead return statement; rule Ada RM 6.5(5), which requires function to have at least one return statement is still satisfied. (Analyze_Attribute): Remove dead exit statement. (Check_Reference): Same as above. * sem_ch12.adb (Instantiate_Formal_Package): Remove dead raise statement; it was inconsistent with other calls to Abandon_Instantiation, which are not followed by a raise statement. * sem_prag.adb (Process_Convention): Remove dead defensive assignment. (Interrupt_State): Remove dead defensive exit statement. (Do_SPARK_Mode): Likewise. * sfn_scan.adb (Scan_String): Remove dead defensive assignment. diff --git a/gcc/ada/gnatls.adb b/gcc/ada/gnatls.adb --- a/gcc/ada/gnatls.adb +++ b/gcc/ada/gnatls.adb @@ -319,7 +319,6 @@ procedure Gnatls is Write_Eol; Error_Msg ("wrong ALI format, can't find dependency line for $ in {"); Exit_Program (E_Fatal); - return No_Sdep_Id; end Corresponding_Sdep_Entry; ------------------------- @@ -2051,7 +2050,6 @@ begin if License then if Arg_Count = 2 then Output_License_Information; - Exit_Program (E_Success); else Set_Standard_Error; diff --git a/gcc/ada/libgnat/a-exstat.adb b/gcc/ada/libgnat/a-exstat.adb --- a/gcc/ada/libgnat/a-exstat.adb +++ b/gcc/ada/libgnat/a-exstat.adb @@ -109,13 +109,6 @@ package body Stream_Attributes is Raise_Exception (Program_Error'Identity, "bad exception occurrence in stream input"); - - -- The following junk raise of Program_Error is required because - -- this is a No_Return procedure, and unfortunately Raise_Exception - -- can return (this particular call can't, but the back end is not - -- clever enough to know that). - - raise Program_Error; end Bad_EO; procedure Next_String is diff --git a/gcc/ada/libgnat/g-awk.adb b/gcc/ada/libgnat/g-awk.adb --- a/gcc/ada/libgnat/g-awk.adb +++ b/gcc/ada/libgnat/g-awk.adb @@ -1211,7 +1211,6 @@ package body GNAT.AWK is Exceptions.Raise_Exception (E, '[' & Filename & ':' & Line & "] " & Message); - raise Constraint_Error; -- to please GNAT as this is a No_Return proc end Raise_With_Info; --------------- diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -4747,7 +4747,6 @@ package body Sem_Attr is Error_Attr ("prefix of attribute % cannot reference local entities", Nod); - return Abandon; else return OK; end if; @@ -4989,7 +4988,6 @@ package body Sem_Attr is else Error_Attr ("attribute % cannot appear in body or accept statement", N); - exit; end if; end loop; @@ -5383,7 +5381,6 @@ package body Sem_Attr is Error_Attr ("prefix of attribute % cannot reference local entities", Nod); - return Abandon; -- Otherwise keep inspecting the prefix diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -10572,7 +10572,6 @@ package body Sem_Ch12 is Error_Msg_N ("expect package instance to instantiate formal", Actual); Abandon_Instantiation (Actual); - raise Program_Error; else Actual_Pack := Entity (Actual); diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -8336,7 +8336,6 @@ package body Sem_Prag is Error_Pragma_Arg ("argument of pragma% must be subprogram or access type", Arg2); - Subp := Empty; end if; -- ISO C requires a named parameter before the ellipsis, so a @@ -18641,7 +18640,6 @@ package body Sem_Prag is Interrupt_States.Table (IST_Num).Pragma_Loc; Error_Pragma_Arg ("state conflicts with that given #", Arg2); - exit; end if; IST_Num := IST_Num + 1; @@ -23762,7 +23760,6 @@ package body Sem_Prag is else Pragma_Misplaced; - exit; end if; Prev (Stmt); diff --git a/gcc/ada/sfn_scan.adb b/gcc/ada/sfn_scan.adb --- a/gcc/ada/sfn_scan.adb +++ b/gcc/ada/sfn_scan.adb @@ -622,7 +622,6 @@ package body SFN_Scan is Q := '%'; else Error ("bad string"); - Q := '"'; end if; -- Scan out the string, B points to first char