public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1630] [Ada] Refine heuristics for unreachable-code warnings
Date: Tue, 12 Jul 2022 12:26:02 +0000 (GMT)	[thread overview]
Message-ID: <20220712122602.287143857C76@sourceware.org> (raw)

https://gcc.gnu.org/g:e124352c0ada83486926f110c8b28a0a431c98b4

commit r13-1630-ge124352c0ada83486926f110c8b28a0a431c98b4
Author: Bob Duff <duff@adacore.com>
Date:   Fri Jun 24 14:25:48 2022 -0400

    [Ada] Refine heuristics for unreachable-code warnings
    
    This patch refines the heuristics for when we warn about unreachable
    code, to avoid common false alarms.
    
    gcc/ada/
    
            * sem_ch5.adb (Check_Unreachable_Code): Refine heuristics.
            * sem_util.ads, sem_util.adb (Is_Static_Constant_Name): Remove
            this; instead we have a new function Is_Simple_Case in
            Sem_Ch5.Check_Unreachable_Code.

Diff:
---
 gcc/ada/sem_ch5.adb  | 28 ++++++++++++++++++++++++++--
 gcc/ada/sem_util.adb | 12 ------------
 gcc/ada/sem_util.ads |  3 ---
 3 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index b2a3661900c..e1b57222288 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -4393,6 +4393,31 @@ package body Sem_Ch5 is
    ----------------------------
 
    procedure Check_Unreachable_Code (N : Node_Id) is
+
+      function Is_Simple_Case (N : Node_Id) return Boolean;
+      --  N is the condition of an if statement. True if N is simple enough
+      --  that we should not set Unblocked_Exit_Count in the special case
+      --  below.
+
+      --------------------
+      -- Is_Simple_Case --
+      --------------------
+
+      function Is_Simple_Case (N : Node_Id) return Boolean is
+      begin
+         return
+            Is_Trivial_Boolean (N)
+           or else
+            (Comes_From_Source (N)
+               and then Is_Static_Expression (N)
+               and then Nkind (N) in N_Identifier | N_Expanded_Name
+               and then Ekind (Entity (N)) = E_Constant)
+           or else
+            (not In_Instance
+               and then Nkind (Original_Node (N)) = N_Op_Not
+               and then Is_Simple_Case (Right_Opnd (Original_Node (N))));
+      end Is_Simple_Case;
+
       Error_Node : Node_Id;
       Nxt        : Node_Id;
       P          : Node_Id;
@@ -4574,8 +4599,7 @@ package body Sem_Ch5 is
               and then No (Else_Statements (P))
               and then Is_OK_Static_Expression (Condition (P))
               and then Is_True (Expr_Value (Condition (P)))
-              and then not Is_Trivial_Boolean (Condition (P))
-              and then not Is_Static_Constant_Name (Condition (P))
+              and then not Is_Simple_Case (Condition (P))
             then
                pragma Assert (Unblocked_Exit_Count = 2);
                Unblocked_Exit_Count := 0;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index cfbf01092a6..0e65cbf4fb7 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -21532,18 +21532,6 @@ package body Sem_Util is
         and then Entity (N) in Standard_True | Standard_False;
    end Is_Trivial_Boolean;
 
-   -----------------------------
-   -- Is_Static_Constant_Name --
-   -----------------------------
-
-   function Is_Static_Constant_Name (N : Node_Id) return Boolean is
-   begin
-      return Comes_From_Source (N)
-        and then Is_Static_Expression (N)
-        and then Nkind (N) in N_Identifier | N_Expanded_Name
-        and then Ekind (Entity (N)) = E_Constant;
-   end Is_Static_Constant_Name;
-
    --------------------------------------
    -- Is_Unchecked_Conversion_Instance --
    --------------------------------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index e5b1118d979..64cf5d041dd 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -2485,9 +2485,6 @@ package Sem_Util is
    --  Determine whether source node N denotes "True" or "False". Note that
    --  this is not true for expressions that got folded to True or False.
 
-   function Is_Static_Constant_Name (N : Node_Id) return Boolean;
-   --  True if N is a name that statically denotes a static constant.
-
    function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean;
    --  Determine whether an arbitrary entity denotes an instance of function
    --  Ada.Unchecked_Conversion.


                 reply	other threads:[~2022-07-12 12:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220712122602.287143857C76@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).