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 warnings about unset references
Date: Fri, 4 Nov 2022 14:58:31 +0100 [thread overview]
Message-ID: <20221104135831.86995-1-poulhies@adacore.com> (raw)
From: Piotr Trojanek <trojanek@adacore.com>
Cleanup related to new checks for unset references.
gcc/ada/
* sem_util.adb
(In_Pragma_Expression): Add standard guard against searching too
far.
(In_Quantified_Expression): Likewise.
* sem_warn.adb
(May_Need_Initialized_Actual): Remove redundant parens.
(Check_References): Remove guard that duplicates a condition from
the enclosing if-statement; only assign E1T variable when
necessary.
(Within_Postcondition): Fix layout.
(No_Warn_On_In_Out): Balance parens in comment.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_util.adb | 13 +++++++++++++
gcc/ada/sem_warn.adb | 18 ++++++------------
2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 80d07eb0023..5c495761df1 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -14794,8 +14794,15 @@ package body Sem_Util is
loop
if No (P) then
return False;
+
+ -- Prevent the search from going too far
+
+ elsif Is_Body_Or_Package_Declaration (P) then
+ return False;
+
elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
return True;
+
else
P := Parent (P);
end if;
@@ -14871,6 +14878,12 @@ package body Sem_Util is
loop
if No (P) then
return False;
+
+ -- Prevent the search from going too far
+
+ elsif Is_Body_Or_Package_Declaration (P) then
+ return False;
+
elsif Nkind (P) = N_Quantified_Expression then
return True;
else
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 509efa50af3..423754f5df8 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -928,7 +928,7 @@ package body Sem_Warn is
if not Is_Generic_Type (T) then
null;
- elsif (Nkind (Par)) = N_Private_Extension_Declaration then
+ elsif Nkind (Par) = N_Private_Extension_Declaration then
-- We only indicate the first such variable in the generic.
@@ -936,7 +936,7 @@ package body Sem_Warn is
Set_Uninitialized_Variable (Par, Ent);
end if;
- elsif (Nkind (Par)) = N_Formal_Type_Declaration
+ elsif Nkind (Par) = N_Formal_Type_Declaration
and then Nkind (Formal_Type_Definition (Par)) =
N_Formal_Private_Type_Definition
then
@@ -1151,8 +1151,6 @@ package body Sem_Warn is
E1 := First_Entity (E);
while Present (E1) loop
- E1T := Etype (E1);
-
-- We are only interested in source entities. We also don't issue
-- warnings within instances, since the proper place for such
-- warnings is on the template when it is compiled, and we don't
@@ -1161,6 +1159,8 @@ package body Sem_Warn is
if Comes_From_Source (E1)
and then Instantiation_Location (Sloc (E1)) = No_Location
then
+ E1T := Etype (E1);
+
-- We are interested in variables and out/in-out parameters, but
-- we exclude protected types, too complicated to worry about.
@@ -1648,11 +1648,6 @@ package body Sem_Warn is
not Is_Package_Or_Generic_Package
(Cunit_Entity (Current_Sem_Unit))))
- -- Exclude instantiations, since there is no reason why every
- -- entity in an instantiation should be referenced.
-
- and then Instantiation_Location (Sloc (E1)) = No_Location
-
-- Exclude formal parameters from bodies if the corresponding
-- spec entity has been referenced in the case where there is
-- a separate spec.
@@ -2001,8 +1996,7 @@ package body Sem_Warn is
P := Parent (Nod);
if Nkind (P) = N_Pragma
- and then Pragma_Name (P) =
- Name_Test_Case
+ and then Pragma_Name (P) = Name_Test_Case
and then Nod = Test_Case_Arg (P, Name_Ensures)
then
return True;
@@ -3028,7 +3022,7 @@ package body Sem_Warn is
-- if we have seen the address of the subprogram being taken, or if the
-- subprogram is used as a generic actual (in the latter cases the
-- context may force use of IN OUT, even if the parameter is not
- -- modified for this particular case.
+ -- modified for this particular case).
-----------------------
-- No_Warn_On_In_Out --
--
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=20221104135831.86995-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).