[Bug libfortran/124668] STOP statement should probably flush OUTPUT_UNIT before issuing its message on ERROR_UNIT
jvdelisle at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Mar 29 20:15:22 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124668
Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2026-03-29
CC| |jvdelisle at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jvdelisle at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #8 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
(In reply to Steve Kargl from comment #7)
> (In reply to Walter Spector from comment #6)
>
> > One can work around the problem by placing a FLUSH (OUTPUT_UNIT) statement
> > just prior to the STOP. But this seems silly.
It seems we do not have a concensus about whether this is a problem or not.
>
> Seems like good defensive programming as stdout and stdin
> are the same "external file" (i.e., device).
>
> And as already mentions, there are two environmental
> variables available to control buffering.
I did compare to flang and intel compilers and their behaviour agrees with
Walter. The following trivial patch seems to do it. I also regression tested it
and all is good. I would prefer to wait for after the 16 release if we do this.
diff --git a/libgfortran/runtime/stop.c b/libgfortran/runtime/stop.c
index 9be1b4b83ea..1b22cec040e 100644
--- a/libgfortran/runtime/stop.c
+++ b/libgfortran/runtime/stop.c
@@ -124,6 +124,7 @@ stop_numeric (int code, bool quiet)
if (!quiet)
{
report_exception ();
+ flush_all_units ();
st_printf ("STOP %d\n", code);
}
exit (code);
@@ -138,6 +139,7 @@ stop_string (const char *string, size_t len, bool quiet)
if (!quiet)
{
report_exception ();
+ flush_all_units ();
if (string)
{
struct iovec iov[3];
@@ -169,6 +171,7 @@ error_stop_string (const char *string, size_t len, bool
quiet)
{
struct iovec iov[3];
report_exception ();
+ flush_all_units ();
iov[0].iov_base = (char*) "ERROR STOP ";
iov[0].iov_len = strlen (iov[0].iov_base);
iov[1].iov_base = (char*) string;
@@ -192,6 +195,7 @@ error_stop_numeric (int code, bool quiet)
if (!quiet)
{
report_exception ();
+ flush_all_units ();
st_printf ("ERROR STOP %d\n", code);
}
exit_error (code);
More information about the Gcc-bugs
mailing list