public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r15-417] ada: Fix crash on Compile_Time_Warning in dead code
@ 2024-05-13  8:37 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2024-05-13  8:37 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b3eef3b124d1eee9cd261fb072d6e1667cd2501a

commit r15-417-gb3eef3b124d1eee9cd261fb072d6e1667cd2501a
Author: Bob Duff <duff@adacore.com>
Date:   Wed Jan 31 09:30:06 2024 -0500

    ada: Fix crash on Compile_Time_Warning in dead code
    
    If a pragma Compile_Time_Warning triggers, and the pragma
    is later removed because it is dead code, then the compiler
    can return a bad exit code. This causes gprbuild to report
    "*** compilation phase failed".
    
    This is because Total_Errors_Detected, which is declared as Nat,
    goes negative, causing Constraint_Error. In assertions-off mode,
    the Constraint_Error is not detected, but the compiler nonetheless
    reports a bad exit code.
    
    This patch prevents that negative count.
    
    gcc/ada/
    
            * errout.adb (Output_Messages): Protect against the total going
            negative.

Diff:
---
 gcc/ada/errout.adb | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index d28a410f47b7..c4761bd1bc9e 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -3399,11 +3399,16 @@ package body Errout is
 
       if Warning_Mode = Treat_As_Error then
          declare
-            Compile_Time_Pragma_Warnings : constant Int :=
+            Compile_Time_Pragma_Warnings : constant Nat :=
                Count_Compile_Time_Pragma_Warnings;
-         begin
-            Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected
+            Total : constant Int := Total_Errors_Detected + Warnings_Detected
                - Warning_Info_Messages - 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 :=
                Warning_Info_Messages + Compile_Time_Pragma_Warnings;
          end;

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

only message in thread, other threads:[~2024-05-13  8:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13  8:37 [gcc r15-417] ada: Fix crash on Compile_Time_Warning in dead code 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).