diff mbox

[Ada] Adapt detection of errors to gnat2why changes of Warning_Mode

Message ID 20170112160122.GA141502@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Jan. 12, 2017, 4:01 p.m. UTC
In gnat2why, the executable used in GNATprove, Warning_Mode is changed
between the initial and final work done in frontend (controlled by -gnatws
in particular) and the work in between done in gnat2why (controlled by
GNATprove switch --warnings). This requires storing the detection of an
error related to warnings treated as errors between all phases.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-01-12  Yannick Moy  <moy@adacore.com>

	* errout.adb, errout.ads (Initialize): Factor common treatment
	in Reset_Warnings.
	(Reset_Warnings): New procedure to reset counts related to warnings.
	(Record_Compilation_Errors): New variable to store the presence of an
	error, used in gnat2why to allow changing the Warning_Mode.
	(Compilation_Errors): Use new variable Record_Compilation_Errors to
	store the presence of an error.
diff mbox

Patch

Index: errout.adb
===================================================================
--- errout.adb	(revision 244352)
+++ errout.adb	(working copy)
@@ -60,6 +60,13 @@ 
    Finalize_Called : Boolean := False;
    --  Set True if the Finalize routine has been called
 
+   Record_Compilation_Errors : Boolean := False;
+   --  Record that a compilation error was witnessed during a given phase of
+   --  analysis for gnat2why. This is needed as Warning_Mode is modified twice
+   --  in gnat2why, hence Erroutc.Compilation_Errors can only return a suitable
+   --  value for each phase of analysis separately. This is updated at each
+   --  call to Compilation_Errors.
+
    Warn_On_Instance : Boolean;
    --  Flag set true for warning message to be posted on instance
 
@@ -236,8 +243,17 @@ 
    begin
       if not Finalize_Called then
          raise Program_Error;
+
+      --  Record that a compilation error was witnessed during a given phase of
+      --  analysis for gnat2why. This is needed as Warning_Mode is modified
+      --  twice in gnat2why, hence Erroutc.Compilation_Errors can only return a
+      --  suitable value for each phase of analysis separately.
+
       else
-         return Erroutc.Compilation_Errors;
+         Record_Compilation_Errors := Record_Compilation_Errors or else
+           Erroutc.Compilation_Errors;
+
+         return Record_Compilation_Errors;
       end if;
    end Compilation_Errors;
 
@@ -1615,13 +1631,13 @@ 
       Last_Error_Msg := No_Error_Msg;
       Serious_Errors_Detected := 0;
       Total_Errors_Detected := 0;
-      Warnings_Treated_As_Errors := 0;
-      Warnings_Detected := 0;
-      Info_Messages := 0;
-      Warnings_As_Errors_Count := 0;
       Cur_Msg := No_Error_Msg;
       List_Pragmas.Init;
 
+      --  Reset counts for warnings
+
+      Reset_Warnings;
+
       --  Initialize warnings tables
 
       Warnings.Init;
@@ -2357,6 +2373,18 @@ 
       end if;
    end Remove_Warning_Messages;
 
+   --------------------
+   -- Reset_Warnings --
+   --------------------
+
+   procedure Reset_Warnings is
+   begin
+      Warnings_Treated_As_Errors := 0;
+      Warnings_Detected := 0;
+      Info_Messages := 0;
+      Warnings_As_Errors_Count := 0;
+   end Reset_Warnings;
+
    ----------------------
    -- Adjust_Name_Case --
    ----------------------
Index: errout.ads
===================================================================
--- errout.ads	(revision 244350)
+++ errout.ads	(working copy)
@@ -803,6 +803,11 @@ 
    --  Remove warnings on all elements of a list (Calls Remove_Warning_Messages
    --  on each element of the list, see above).
 
+   procedure Reset_Warnings;
+   --  Reset the counts related to warnings. This is used both to initialize
+   --  these counts and to reset them after each phase of analysis for a given
+   --  value of Opt.Warning_Mode in gnat2why.
+
    procedure Set_Ignore_Errors (To : Boolean);
    --  Following a call to this procedure with To=True, all error calls are
    --  ignored. A call with To=False restores the default treatment in which
@@ -852,9 +857,9 @@ 
    function Compilation_Errors return Boolean;
    --  Returns True if errors have been detected, or warnings in -gnatwe (treat
    --  warnings as errors) mode. Note that it is mandatory to call Finalize
-   --  before calling this routine. Always returns False in formal verification
-   --  mode, because errors issued when analyzing code are not compilation
-   --  errors, and should not result in exiting with an error status.
+   --  before calling this routine. To account for changes to Warning_Mode in
+   --  gnat2why between phases, the past or current presence of an error is
+   --  recorded in a global variable at each call.
 
    procedure Error_Msg_CRT (Feature : String; N : Node_Id);
    --  Posts a non-fatal message on node N saying that the feature identified