]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
The problem is that diagnostic_action_after_output tries to delete the active pretty...
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Wed, 24 Jun 2015 22:16:42 +0000 (22:16 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Wed, 24 Jun 2015 22:16:42 +0000 (22:16 +0000)
The problem is that diagnostic_action_after_output tries to delete the active
pretty-printer which tries to delete its output_buffer, which is normally
dynamically allocated via placement-new, but the output_buffer used by the
error_buffer of Fortran is statically allocated. Being statically allocated
simplifies a lot pushing/poping several instances of error_buffer.

The solution is to reset the active output_buffer back to the default one
before calling diagnostic_action_after_output. This is a bit ugly, because this
function does use the output_buffer, however, at the point that Fortran calls
it, both are in an equivalent state, thus there is no visible difference.

gcc/testsuite/ChangeLog:

2015-06-24  Manuel López-Ibáñez  <manu@gcc.gnu.org>

PR fortran/66528
* gfortran.dg/maxerrors.f90: New test.

gcc/fortran/ChangeLog:

2015-06-24  Manuel López-Ibáñez  <manu@gcc.gnu.org>

PR fortran/66528
* error.c (gfc_warning_check): Restore the default output_buffer
before calling diagnostic_action_after_output.
(gfc_error_check): Likewise.
(gfc_diagnostics_init): Add comment.

From-SVN: r224926

gcc/fortran/ChangeLog
gcc/fortran/error.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/maxerrors.f90 [new file with mode: 0644]

index 808bf7e70a1a20f38ca2a7c91c365acb2605b3e0..52f24b20b7a571ad3f57510012c58bc53b9a102a 100644 (file)
@@ -1,3 +1,11 @@
+2015-06-24  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR fortran/66528
+       * error.c (gfc_warning_check): Restore the default output_buffer
+       before calling diagnostic_action_after_output.
+       (gfc_error_check): Likewise.
+       (gfc_diagnostics_init): Add comment.
+
 2015-06-23  Andre Vehreschild  <vehre@gmx.de>
 
        PR fortran/64674
index 2512cfc36aa7eeacfa12b87068c5460f00a8a433..c7d8581f9708bac7e587b3bec5b7dbca90cf6c0a 100644 (file)
@@ -1249,7 +1249,6 @@ gfc_clear_warning (void)
 void
 gfc_warning_check (void)
 {
-  /* This is for the new diagnostics machinery.  */
   if (! gfc_output_buffer_empty_p (pp_warning_buffer))
     {
       pretty_printer *pp = global_dc->printer;
@@ -1259,10 +1258,10 @@ gfc_warning_check (void)
       warningcount += warningcount_buffered;
       werrorcount += werrorcount_buffered;
       gcc_assert (warningcount_buffered + werrorcount_buffered == 1);
+      pp->buffer = tmp_buffer;
       diagnostic_action_after_output (global_dc, 
                                      warningcount_buffered 
                                      ? DK_WARNING : DK_ERROR);
-      pp->buffer = tmp_buffer;
     }
 }
 
@@ -1381,8 +1380,8 @@ gfc_error_check (void)
       pp_really_flush (pp);
       ++errorcount;
       gcc_assert (gfc_output_buffer_empty_p (pp_error_buffer));
-      diagnostic_action_after_output (global_dc, DK_ERROR);
       pp->buffer = tmp_buffer;
+      diagnostic_action_after_output (global_dc, DK_ERROR);
       return true;
     }
 
@@ -1472,6 +1471,8 @@ gfc_diagnostics_init (void)
   global_dc->caret_chars[1] = '2';
   pp_warning_buffer = new (XNEW (output_buffer)) output_buffer ();
   pp_warning_buffer->flush_p = false;
+  /* pp_error_buffer is statically allocated.  This simplifies memory
+     management when using gfc_push/pop_error. */
   pp_error_buffer = &(error_buffer.buffer);
   pp_error_buffer->flush_p = false;
 }
index e9f747bd69c7cbc151aacf178fc346c5833f82da..699e70c4a8540aa6b24482230f86613bd20c3b0a 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-24  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR fortran/66528
+       * gfortran.dg/maxerrors.f90: New test.
+
 2015-06-08  DJ Delorie  <dj@redhat.com>
 
        * gcc.dg/torture/pr66345.c: Fix assumption about size_t type.
diff --git a/gcc/testsuite/gfortran.dg/maxerrors.f90 b/gcc/testsuite/gfortran.dg/maxerrors.f90
new file mode 100644 (file)
index 0000000..6c3232d
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! { dg-options "-fmax-errors=1" }
+! PR66528
+! { dg-prune-output "compilation terminated" }
+program main
+  read (*,*) n
+  if (n<0) then
+    print *,foo
+  end ! { dg-error "END IF statement expected" }
+    print *,bar
+end program main
+