[gcc r11-4234] [Ada] Cleanup repeated code in checks for unused WITH clauses

Pierre-Marie de Rodat pmderodat@gcc.gnu.org
Thu Oct 22 12:12:03 GMT 2020


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

commit r11-4234-g1c583927a57a06e9f94de4c982ae827d227543ab
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Tue Aug 11 16:14:19 2020 +0200

    [Ada] Cleanup repeated code in checks for unused WITH clauses
    
    gcc/ada/
    
            * sem_warn.adb (Check_One_Unit): Avoid repeated calls by using a
            local variable Lunit; remove local constant Eitem, which was
            identical to Lunit.

Diff:
---
 gcc/ada/sem_warn.adb | 94 ++++++++++++++++++++++++----------------------------
 1 file changed, 43 insertions(+), 51 deletions(-)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 89e5696ef01..aeea3186572 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -2507,7 +2507,7 @@ package body Sem_Warn is
                      --  package with only a linker options pragma and nothing
                      --  else or a pragma elaborate with a body library task).
 
-                     elsif Has_Visible_Entities (Entity (Name (Item))) then
+                     elsif Has_Visible_Entities (Lunit) then
                         Error_Msg_N -- CODEFIX
                           ("?u?unit& is not referenced!", Name (Item));
                      end if;
@@ -2582,58 +2582,50 @@ package body Sem_Warn is
                            --  Else the warning may be needed
 
                            else
-                              declare
-                                 Eitem : constant Entity_Id :=
-                                           Entity (Name (Item));
-
-                              begin
-                                 --  Warn if we unreferenced flag set and we
-                                 --  have not had serious errors. The reason we
-                                 --  inhibit the message if there are errors is
-                                 --  to prevent false positives from disabling
-                                 --  expansion.
-
-                                 if not Has_Unreferenced (Eitem)
-                                   and then Serious_Errors_Detected = 0
+                              --  Warn if we unreferenced flag set and we have
+                              --  not had serious errors. The reason we inhibit
+                              --  the message if there are errors is to prevent
+                              --  false positives from disabling expansion.
+
+                              if not Has_Unreferenced (Lunit)
+                                and then Serious_Errors_Detected = 0
+                              then
+                                 --  Get possible package renaming
+
+                                 Pack := Find_Package_Renaming (Munite, Lunit);
+
+                                 --  No warning if either the package or its
+                                 --  renaming is used as a generic actual.
+
+                                 if Used_As_Generic_Actual (Lunit)
+                                   or else
+                                     (Present (Pack)
+                                       and then
+                                         Used_As_Generic_Actual (Pack))
+                                 then
+                                    exit;
+                                 end if;
+
+                                 --  Here we give the warning
+
+                                 Error_Msg_N -- CODEFIX
+                                   ("?u?no entities of & are referenced!",
+                                    Name (Item));
+
+                                 --  Flag renaming of package as well. If
+                                 --  the original package has warnings off,
+                                 --  we suppress the warning on the renaming
+                                 --  as well.
+
+                                 if Present (Pack)
+                                   and then not Has_Warnings_Off (Lunit)
+                                   and then not Has_Unreferenced (Pack)
                                  then
-                                    --  Get possible package renaming
-
-                                    Pack :=
-                                      Find_Package_Renaming (Munite, Lunit);
-
-                                    --  No warning if either the package or its
-                                    --  renaming is used as a generic actual.
-
-                                    if Used_As_Generic_Actual (Eitem)
-                                      or else
-                                        (Present (Pack)
-                                          and then
-                                            Used_As_Generic_Actual (Pack))
-                                    then
-                                       exit;
-                                    end if;
-
-                                    --  Here we give the warning
-
-                                    Error_Msg_N -- CODEFIX
-                                      ("?u?no entities of & are referenced!",
-                                       Name (Item));
-
-                                    --  Flag renaming of package as well. If
-                                    --  the original package has warnings off,
-                                    --  we suppress the warning on the renaming
-                                    --  as well.
-
-                                    if Present (Pack)
-                                      and then not Has_Warnings_Off (Lunit)
-                                      and then not Has_Unreferenced (Pack)
-                                    then
-                                       Error_Msg_NE -- CODEFIX
-                                         ("?u?no entities of& are referenced!",
-                                          Unit_Declaration_Node (Pack), Pack);
-                                    end if;
+                                    Error_Msg_NE -- CODEFIX
+                                      ("?u?no entities of& are referenced!",
+                                       Unit_Declaration_Node (Pack), Pack);
                                  end if;
-                              end;
+                              end if;
                            end if;
 
                            exit;


More information about the Gcc-cvs mailing list