public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED] ada: Cleanup code for unreferenced variables
Date: Fri,  4 Nov 2022 14:58:38 +0100	[thread overview]
Message-ID: <20221104135838.87055-1-poulhies@adacore.com> (raw)

From: Piotr Trojanek <trojanek@adacore.com>

Further cleanups related to warnings about unreferenced objects.

gcc/ada/

	* sem_warn.adb (Check_References): Remove useless query for "spec"
	of a variable; refactor nested if-statements into a single
	condition.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_warn.adb | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 423754f5df8..a7f220bfbc7 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1221,7 +1221,7 @@ package body Sem_Warn is
                elsif Warn_On_Constant
                  and then Ekind (E1) = E_Variable
                  and then Has_Initial_Value (E1)
-                 and then Never_Set_In_Source_Check_Spec (E1)
+                 and then Never_Set_In_Source (E1)
                  and then not Generic_Package_Spec_Entity (E1)
                then
                   --  A special case, if this variable is volatile and not
@@ -1248,24 +1248,15 @@ package body Sem_Warn is
                   --  Here we give the warning if referenced and no pragma
                   --  Unreferenced or Unmodified is present.
 
-                  else
-                     --  Variable case
-
-                     if Ekind (E1) = E_Variable then
-                        if Referenced_Check_Spec (E1)
-                          and then not Has_Pragma_Unreferenced_Check_Spec (E1)
-                          and then not Has_Pragma_Unmodified_Check_Spec (E1)
-                        then
-                           if not Warnings_Off_E1
-                             and then not Has_Junk_Name (E1)
-                           then
-                              Error_Msg_N -- CODEFIX
-                                ("?k?& is not modified, "
-                                 & "could be declared constant!",
-                                 E1);
-                           end if;
-                        end if;
-                     end if;
+                  elsif Referenced (E1)
+                    and then not Has_Unreferenced (E1)
+                    and then not Has_Unmodified (E1)
+                    and then not Warnings_Off_E1
+                    and then not Has_Junk_Name (E1)
+                  then
+                     Error_Msg_N -- CODEFIX
+                       ("?k?& is not modified, could be declared constant!",
+                        E1);
                   end if;
 
                --  Other cases of a variable or parameter never set in source
-- 
2.34.1


                 reply	other threads:[~2022-11-04 13:58 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=20221104135838.87055-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=trojanek@adacore.com \
    /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).