From patchwork Tue Jul 12 12:25:10 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: 55942 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 3F0343836FB2 for ; Tue, 12 Jul 2022 12:25:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F0343836FB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657628742; bh=h9ZBmA0U/+hepytU+wrAM0GpZBs9vEZ0OCgWAKn3PZg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=I6aK6XJ5sZ2DjkEqpkLeGofg0XXnZ8WPrjdyURrp5yLVv/qsbS6FJeei2RKYf4en5 /CgwwR3IUK1ytiAfrGvLzry35lFgft9kZrWyIkydpLMkz0NmlwTYKwQySeUwMrsMaD /aUFL/dz9TLniQ1UIXLfJ0i1yjC4HZ7IWUeBMx6U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 723F3385736A for ; Tue, 12 Jul 2022 12:25:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 723F3385736A Received: by mail-ej1-x629.google.com with SMTP id os14so14017060ejb.4 for ; Tue, 12 Jul 2022 05:25:12 -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=h9ZBmA0U/+hepytU+wrAM0GpZBs9vEZ0OCgWAKn3PZg=; b=D/Ip93GlD8CnqsjRR7DSEfCB7xB8YS8oymfoCrvBMoiWT/Tqn5hxUv5Ggnpeks4Af4 aDuvkA3g0bjQDi4rKkKQFhV+NgOdDGCYQKqfPdsTQGFQGPs42An7xWD+4g6ZxOz4riD+ 2F9YoX+Xjw8IJjnaMzaoG4V0SfZblAqBxZorVKHcYmLvG5f94S3J8pMTwHS+vbjta2P6 oEz5eYXZt8Lt6P7QyBs82jCs5yJdsaYacjmXgSgqQygYweoOMM/o4uG2pwrwTvStj2Vy sNj5c9CrMXJ202ikAqF1DwYnIrkKcF1FzwcWu5/F8kU9+pZc3MQDGRPvkPgYRFoaOTOx PSng== X-Gm-Message-State: AJIora9rcQCStotFqcUhsXMmrj5kFe03XQ5lNFyIoE2sQj8P1XVRecuv mePB68v3a+dS+7EKymHRWDv6KoDwxpG5qQ== X-Google-Smtp-Source: AGRyM1sw79J6M6jIini06cik3xabmAFOH0RJC4tadxZ1FYOnw+mKY4BoI9fUMWGrjLxDKyT9s15/0Q== X-Received: by 2002:a17:907:7b9c:b0:72b:5652:a14a with SMTP id ne28-20020a1709077b9c00b0072b5652a14amr10013849ejc.86.1657628711264; Tue, 12 Jul 2022 05:25:11 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id f10-20020a1709064dca00b006fef557bb7asm3755952ejw.80.2022.07.12.05.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 05:25:10 -0700 (PDT) Date: Tue, 12 Jul 2022 12:25:10 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Warn about unreachable code after calls with No_Return Message-ID: <20220712122510.GA3404592@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, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" GNAT was already warning about unreachable code after raise/goto/exit statements, but not after calls to procedures with No_Return. Now this warning is extended. Also, previously the warning was suppressed for unreachable RETURN after RAISE statements. Now this suppression is narrowed to functions, because only in function such a RETURN statement might be indeed needed (where it is the only RETURN statement of a function). Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch5.adb (Check_Unreachable_Code): Extend suppression to calls with No_Return aspect, but narrow it to functions. * sem_res.adb (Resolve_Call): Warn about unreachable code after calls with No_Return. diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -4418,12 +4418,20 @@ package body Sem_Ch5 is elsif Comes_From_Source (Nxt) and then Is_Statement (Nxt) then - -- Special very annoying exception. If we have a return that - -- follows a raise, then we allow it without a warning, since - -- the Ada RM annoyingly requires a useless return here. - - if Nkind (Original_Node (N)) /= N_Raise_Statement - or else Nkind (Nxt) /= N_Simple_Return_Statement + -- Special very annoying exception. Ada RM 6.5(5) annoyingly + -- requires functions to have at least one return statement, so + -- don't complain about a simple return that follows a raise or a + -- call to procedure with No_Return. + + if not (Present (Current_Subprogram) + and then Ekind (Current_Subprogram) = E_Function + and then (Nkind (Original_Node (N)) = N_Raise_Statement + or else + (Nkind (N) = N_Procedure_Call_Statement + and then Is_Entity_Name (Name (N)) + and then Present (Entity (Name (N))) + and then No_Return (Entity (Name (N))))) + and then Nkind (Nxt) = N_Simple_Return_Statement) then -- The rather strange shenanigans with the warning message -- here reflects the fact that Kill_Dead_Code is very good at diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -62,6 +62,7 @@ with Sem_Case; use Sem_Case; with Sem_Cat; use Sem_Cat; with Sem_Ch3; use Sem_Ch3; with Sem_Ch4; use Sem_Ch4; +with Sem_Ch5; use Sem_Ch5; with Sem_Ch6; use Sem_Ch6; with Sem_Ch8; use Sem_Ch8; with Sem_Ch13; use Sem_Ch13; @@ -7193,6 +7194,14 @@ package body Sem_Res is Analyze_Dimension_Call (N, Nam); + -- Check unreachable code after calls to procedures with No_Return + + if Ekind (Nam) = E_Procedure + and then No_Return (Nam) + then + Check_Unreachable_Code (N); + end if; + -- All done, evaluate call and deal with elaboration issues Eval_Call (N);