https://gcc.gnu.org/g:b3eef3b124d1eee9cd261fb072d6e1667cd2501a
commit r15-417-gb3eef3b124d1eee9cd261fb072d6e1667cd2501a Author: Bob Duff <d...@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;