===================================================================
@@ -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
+
===================================================================
@@ -1247,24 +1247,23 @@ gfc_clear_warning (void)
If so, print the warning. */
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;
output_buffer *tmp_buffer = pp->buffer;
pp->buffer = pp_warning_buffer;
pp_really_flush (pp);
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;
}
}
/* Issue an error. */
@@ -1379,12 +1378,12 @@ gfc_error_check (void)
output_buffer *tmp_buffer = pp->buffer;
pp->buffer = pp_error_buffer;
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;
}
return false;
}
@@ -1470,10 +1469,12 @@ gfc_diagnostics_init (void)
diagnostic_format_decoder (global_dc) = gfc_format_decoder;
global_dc->caret_chars[0] = '1';
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;
}
void