public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1621] [Ada] Warn about unreachable code after calls with No_Return
@ 2022-07-12 12:25 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-07-12 12:25 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1710ba9e5d09493690c5f474a5c37b5c8f5d7b19

commit r13-1621-g1710ba9e5d09493690c5f474a5c37b5c8f5d7b19
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Fri Jun 3 15:18:24 2022 +0200

    [Ada] Warn about unreachable code after calls with No_Return
    
    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).
    
    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:
---
 gcc/ada/sem_ch5.adb | 20 ++++++++++++++------
 gcc/ada/sem_res.adb |  9 +++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 891c57ae9e2..f38c213a42a 100644
--- 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
index 1053cec6dd2..4335940cab5 100644
--- 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);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-12 12:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 12:25 [gcc r13-1621] [Ada] Warn about unreachable code after calls with No_Return Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).