From: Viljar Indus <in...@adacore.com>

Use a live counter Compile_Time_Pragma_Warnings to keep track of
those messages instead of using a method to count them in the end.

gcc/ada/ChangeLog:

        * atree.ads: Add Compile_Time_Pragma_Warnings for counting
        compile time warnings.
        * errout.adb (Initialize): Initialize Compile_Time_Pragma_Warnings.
        (Output_Messages): Use Compile_Time_Pragma_Warnings instead of
        Count_Compile_Time_Pragma_Warnings.
        * erroutc.adb (Compilation_Errors): Likewise.
        (Count_Compile_Time_Pragma_Warnings): Removed.
        (Decrease_Error_Msg_Count): Update Compile_Time_Pragma_Warnings.
        (Increase_Error_Msg_Count): Likewise.
        (Write_Error_Summary): Use Compile_Time_Pragma_Warnings instead of
        Count_Compile_Time_Pragma_Warnings.
        * erroutc.ads (Count_Compile_Time_Pragma_Warnings): Removed.

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

---
 gcc/ada/atree.ads   |  3 +++
 gcc/ada/errout.adb  | 19 ++++++-------------
 gcc/ada/erroutc.adb | 43 ++++++++++++++-----------------------------
 gcc/ada/erroutc.ads |  4 ----
 4 files changed, 23 insertions(+), 46 deletions(-)

diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads
index 802db870933..e17eecc04d0 100644
--- a/gcc/ada/atree.ads
+++ b/gcc/ada/atree.ads
@@ -175,6 +175,9 @@ package Atree is
    --  Number of warnings changed into errors as a result of matching a pattern
    --  given in a Warning_As_Error configuration pragma.
 
+   Compile_Time_Pragma_Warnings : Nat := 0;
+   --  Number of warnings that come from a Compile_Time_Warning pragma
+
    Configurable_Run_Time_Violations : Nat := 0;
    --  Count of configurable run time violations so far. This is used to
    --  suppress certain cascaded error messages when we know that we may not
diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index c1ceaf2815b..58ba6be6189 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -2120,6 +2120,7 @@ package body Errout is
       Warnings_Treated_As_Errors := 0;
       Warnings_Detected := 0;
       Warnings_As_Errors_Count := 0;
+      Compile_Time_Pragma_Warnings := 0;
 
       --  Initialize warnings tables
 
@@ -3126,19 +3127,11 @@ package body Errout is
       end if;
 
       if Warning_Mode = Treat_As_Error then
-         declare
-            Compile_Time_Pragma_Warnings : constant Nat :=
-               Count_Compile_Time_Pragma_Warnings;
-            Total : constant Int := Total_Errors_Detected + Warnings_Detected
-               - Compile_Time_Pragma_Warnings;
-            --  We need to protect against a negative Total here, because
-            --  if a pragma Compile_Time_Warning occurs in dead code, it
-            --  gets counted in Compile_Time_Pragma_Warnings but not in
-            --  Warnings_Detected.
-         begin
-            Total_Errors_Detected := Int'Max (Total, 0);
-            Warnings_Detected := Compile_Time_Pragma_Warnings;
-         end;
+         Total_Errors_Detected :=
+           Total_Errors_Detected
+           + Warnings_Detected
+           - Compile_Time_Pragma_Warnings;
+         Warnings_Detected := Compile_Time_Pragma_Warnings;
       end if;
    end Output_Messages;
 
diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb
index 26095520fa1..fa4dcb80ff4 100644
--- a/gcc/ada/erroutc.adb
+++ b/gcc/ada/erroutc.adb
@@ -237,10 +237,10 @@ package body Erroutc is
       --  Compile_Time_Warning pragma as an error. Warnings_Count is the sum
       --  of both "normal" and Compile_Time_Warning warnings. This means that
       --  there are only one or more non-Compile_Time_Warning warnings when
-      --  Warnings_Count is greater than Count_Compile_Time_Pragma_Warnings.
+      --  Warnings_Count is greater than Compile_Time_Pragma_Warnings.
 
       elsif Warning_Mode = Treat_As_Error
-         and then Warnings_Count > Count_Compile_Time_Pragma_Warnings
+         and then Warnings_Count > Compile_Time_Pragma_Warnings
       then
          return True;
       end if;
@@ -248,26 +248,6 @@ package body Erroutc is
       return False;
    end Compilation_Errors;
 
-   ----------------------------------------
-   -- Count_Compile_Time_Pragma_Warnings  --
-   ----------------------------------------
-
-   function Count_Compile_Time_Pragma_Warnings return Int is
-      Result : Int := 0;
-   begin
-      for J in 1 .. Errors.Last loop
-         begin
-            if Errors.Table (J).Kind = Warning
-               and then Errors.Table (J).Compile_Time_Pragma
-               and then not Errors.Table (J).Deleted
-            then
-               Result := Result + 1;
-            end if;
-         end;
-      end loop;
-      return Result;
-   end Count_Compile_Time_Pragma_Warnings;
-
    ------------------------------
    -- Decrease_Error_Msg_Count --
    ------------------------------
@@ -286,6 +266,11 @@ package body Erroutc is
                Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
             end if;
 
+            if E.Compile_Time_Pragma then
+               Compile_Time_Pragma_Warnings :=
+                 Compile_Time_Pragma_Warnings - 1;
+            end if;
+
          when High_Check | Medium_Check | Low_Check =>
             Check_Messages := Check_Messages - 1;
 
@@ -451,6 +436,11 @@ package body Erroutc is
                end loop;
             end if;
 
+            if E.Compile_Time_Pragma then
+               Compile_Time_Pragma_Warnings :=
+                 Compile_Time_Pragma_Warnings + 1;
+            end if;
+
          when High_Check | Medium_Check | Low_Check =>
             Check_Messages := Check_Messages + 1;
 
@@ -2215,10 +2205,6 @@ package body Erroutc is
       declare
          Warnings_Count : constant Int := Warnings_Detected;
 
-         Compile_Time_Warnings : Int;
-         --  Number of warnings that come from a Compile_Time_Warning
-         --  pragma.
-
          Non_Compile_Time_Warnings : Int;
          --  Number of warnings that do not come from a Compile_Time_Warning
          --  pragmas.
@@ -2233,16 +2219,15 @@ package body Erroutc is
                Write_Char ('s');
             end if;
 
-            Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings;
             Non_Compile_Time_Warnings :=
-               Warnings_Count - Compile_Time_Warnings;
+               Warnings_Count - Compile_Time_Pragma_Warnings;
 
             if Warning_Mode = Treat_As_Error
                and then Non_Compile_Time_Warnings > 0
             then
                Write_Str (" (");
 
-               if Compile_Time_Warnings > 0 then
+               if Compile_Time_Pragma_Warnings > 0 then
                   Write_Int (Non_Compile_Time_Warnings);
                   Write_Str (" ");
                end if;
diff --git a/gcc/ada/erroutc.ads b/gcc/ada/erroutc.ads
index 2c44b5b1487..b5d0578f99f 100644
--- a/gcc/ada/erroutc.ads
+++ b/gcc/ada/erroutc.ads
@@ -625,10 +625,6 @@ package Erroutc is
    --  redundant. If so, the message to be deleted and all its continuations
    --  are marked with the Deleted flag set to True.
 
-   function Count_Compile_Time_Pragma_Warnings return Int;
-   --  Returns the number of warnings in the Errors table that were triggered
-   --  by a Compile_Time_Warning pragma.
-
    function Get_Warning_Option (Id : Error_Msg_Id) return String;
    --  Returns the warning switch causing this warning message or an empty
    --  string is there is none..
-- 
2.43.0

Reply via email to