public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5727] [Ada] Refactor nested loops in warning on unassigned out parameter
@ 2021-12-02 16:28 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-12-02 16:28 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1fde9333dc31007083ac792896820ca29837c342

commit r12-5727-g1fde9333dc31007083ac792896820ca29837c342
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Mon Nov 22 12:15:29 2021 +0100

    [Ada] Refactor nested loops in warning on unassigned out parameter
    
    gcc/ada/
    
            * sem_warn.adb (Warn_On_Unassigned_Out_Parameter): Move inner
            loop at the beginning of subprogram, so it is executed only
            once; fix order in the "add an ad hoc" phrase.

Diff:
---
 gcc/ada/sem_warn.adb | 44 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 3d7e4124e0a..2842a2ccb40 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -4237,8 +4237,7 @@ package body Sem_Warn is
      (Return_Node : Node_Id;
       Scope_Id    : Entity_Id)
    is
-      Form  : Entity_Id;
-      Form2 : Entity_Id;
+      Form : Entity_Id;
 
    begin
       --  Ignore if procedure or return statement does not come from source
@@ -4249,6 +4248,26 @@ package body Sem_Warn is
          return;
       end if;
 
+      --  Before we issue the warning, add an ad hoc defence against the most
+      --  common case of false positives with this warning which is the case
+      --  where there is a Boolean OUT parameter that has been set, and whose
+      --  meaning is "ignore the values of the other parameters". We can't of
+      --  course reliably tell this case at compile time, but the following
+      --  test kills a lot of false positives, without generating a significant
+      --  number of false negatives (missed real warnings).
+
+      Form := First_Formal (Scope_Id);
+      while Present (Form) loop
+         if Ekind (Form) = E_Out_Parameter
+           and then Root_Type (Etype (Form)) = Standard_Boolean
+           and then not Never_Set_In_Source_Check_Spec (Form)
+         then
+            return;
+         end if;
+
+         Next_Formal (Form);
+      end loop;
+
       --  Loop through formals
 
       Form := First_Formal (Scope_Id);
@@ -4263,27 +4282,6 @@ package body Sem_Warn is
            and then Is_Scalar_Type (Etype (Form))
            and then not Present (Unset_Reference (Form))
          then
-            --  Before we issue the warning, an add ad hoc defence against the
-            --  most common case of false positives with this warning which is
-            --  the case where there is a Boolean OUT parameter that has been
-            --  set, and whose meaning is "ignore the values of the other
-            --  parameters". We can't of course reliably tell this case at
-            --  compile time, but the following test kills a lot of false
-            --  positives, without generating a significant number of false
-            --  negatives (missed real warnings).
-
-            Form2 := First_Formal (Scope_Id);
-            while Present (Form2) loop
-               if Ekind (Form2) = E_Out_Parameter
-                 and then Root_Type (Etype (Form2)) = Standard_Boolean
-                 and then not Never_Set_In_Source_Check_Spec (Form2)
-               then
-                  return;
-               end if;
-
-               Next_Formal (Form2);
-            end loop;
-
             --  Here all conditions are met, record possible unset reference
 
             Set_Unset_Reference (Form, Return_Node);


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

only message in thread, other threads:[~2021-12-02 16:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 16:28 [gcc r12-5727] [Ada] Refactor nested loops in warning on unassigned out parameter 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).