public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Cleanup code for warnings about unset references
@ 2022-11-04 13:58 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2022-11-04 13:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

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


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

only message in thread, other threads:[~2022-11-04 13:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 13:58 [COMMITTED] ada: Cleanup code for warnings about unset references Marc Poulhiès

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).