[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-02-13 Thread jvdelisle at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

Jerry DeLisle  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|WAITING |RESOLVED

--- Comment #11 from Jerry DeLisle  ---
Fixed on trunk. Thanks for report.

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-02-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #10 from CVS Commits  ---
The master branch has been updated by Jerry DeLisle :

https://gcc.gnu.org/g:19c023241020e3b6f5c38f47447bc0fcbe9fef5f

commit r11-7183-g19c023241020e3b6f5c38f47447bc0fcbe9fef5f
Author: Jerry DeLisle 
Date:   Wed Feb 10 19:37:52 2021 -0800

libgfortran: Fix unwanted end-of-record by checking if seen_dollar.

libgfortran/ChangeLog:

PR libfortran/98825
* io/transfer.c (next_record_w): Insert check for seen_dollar and
if
so, skip issueing next record.

gcc/testsuite/ChangeLog:

PR libfortran/98825
* gfortran.dg/dollar_edit_descriptor_4.f: New test.

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-31 Thread jvdelisle at charter dot net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #9 from Jerry DeLisle  ---
The folowing patch fixes this and regression tests OK.

diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 8ab0583dd55..27bee9d4e01 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -4020,6 +4020,8 @@ next_record_w (st_parameter_dt *dtp, int done)
}
}
}
+  else if (dtp->u.p.seen_dollar == 1)
+   break;
   /* Handle legacy CARRIAGECONTROL line endings.  */
   else if (dtp->u.p.current_unit->flags.cc == CC_FORTRAN)
next_record_cc (dtp);

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-30 Thread jvdelisle at charter dot net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #8 from Jerry DeLisle  ---
I agree with your comment #7

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-30 Thread max.pd at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #7 from max.pd at gmx dot de ---
This DEC-F77 specification seems to be very adequate for the -fdec compiler
flag. For general use of the '$' in format expressions (even without the
compiler flag), it would not make much sense. Here it's the current
"ADVANCE='NO'" interpretation for single records that fits well. For multiple
records it would be coherent to have no carriage returns between the records
either.

I've tested it with flang (LLVM) and with the older OpenWatcom Fortran, and
they both behave like expected. They don't write carriage returns between the
records,
when the '$' is given in the format expression.

Of course the behavior changes for internal files. I guess it is standard that
internal files will write each record to a single field of an array. And the
program will abbort with an error, when the array is too small to take all the
records. This seems to be fully implemented in gfortran and works well in all
tests I made.

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-29 Thread jvdelisle at charter dot net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #6 from Jerry DeLisle  ---
I found the DEC F77 reference.  I wanted to capture this somewhere for future
reference:

o  MESSAGE:  Extension to FORTRAN-77:  nonstandard FORMAT
 statement item

 EXPLANATION:  The following format field descriptors are
 extensions to FORTRAN-77:

Descriptor  Aspect
--  --
$   All forms
A,L,I,F,E,G,D   Default field width forms
P   Without scale factor

and then:

$

 In a format specification, the dollar sign character ($) modifies
 the carriage control specified by the first character of the
 record.  It only affects the files for which the 'FORTRAN' carriage
 control attribute is in effect.

 On U*X systems, it also affects files if 'LIST' is in effect.

 In an input statement, the $ descriptor is ignored.

 In an output statement, the following rules apply:

- If the first character of the record is 0, 1, or
  ASCII NUL, the $ descriptor is ignored.

- If the first character of the record is a space or
  plus sign (+), the $ descriptor suppresses carriage
  return (after printing the record).

 For terminal I/O, whenever trailing carriage return control is
 suppressed by the $ descriptor, a typed response follows output on
 the same line.

I am working on it.

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-27 Thread max.pd at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #5 from max.pd at gmx dot de ---
The -fdec compiler flag provides a possible work around. When opening a Unit
with CARRIAGECONTROL='NONE' (an option available with DEC extensions in
gfortran), the program won't show the unexpected behavior any more. But there
would be no way to enable the carriage return between records for that io-unit
omitting '$' in the format expression. This work around makes it necessary to
open a new unit for stdout output:

   OPEN (UNIT=7, FILE='/dev/stdout', CARRIAGECONTROL='NONE')

 This feature is documented in:

https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gfortran/Extended-I_002fO-specifiers.html

The '$'-fin format works well for gfortran on single records without any
compiler flags. So it might be coherent, to make a patch, that affects the full
scope of the '$' format expressions, even those compiled without the -fdec
compiler flags. So the patch would cover all possible occurrences of the
unexpected behavior when writing multiple record output.

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-26 Thread jvdelisle at charter dot net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

Jerry DeLisle  changed:

   What|Removed |Added

 CC||jvdelisle at charter dot net

--- Comment #4 from Jerry DeLisle  ---
Yes, this can be patched.  I would like to confirm if this is old DEC feature
so I know whether it should go behind one of the DEC compiler flags.

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-25 Thread max.pd at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #3 from max.pd at gmx dot de ---
Here some details to outline the issue:

The problem is affecting

1) "gcc/libgfortran/io/format.c"
2) "gcc/libgfortran/io/transfer.c"

of the gcc source tree.


The feature, implemented as FMT_DOLLAR
can be found in "format.c" (lines 794 to 798)

794:  case FMT_DOLLAR:
795:  get_fnode (fmt, , , FMT_DOLLAR);
796:  tail->repeat = 1;
797:  notify_std (>common, GFC_STD_GNU, "Extension: $ descriptor");
798:  goto between_desc;

--> calling "get_fnode" with FMT_DOLLAR in "format.c" (lines 215-242)

215:  get_fnode (format_data *fmt, fnode **head, fnode **tail, format_token t)
216:  {
217:fnode *f;
...
238:f->format = t;
...
241:return f;
242:  }

f->format is disposed in "transfer.c" (lines 1470-1822)

1462:t = f->format;
...
1470:switch (t)
1471:  {
...
1799:  case FMT_DOLLAR:
1800:consume_data_flag = 0;
1801:dtp->u.p.seen_dollar = 1;
1802:break;
...
1822:  }

u.p.seen_dollar for its part determins u.p.eor_condition = 1 
in "transfer.c" (lines 399-400)

399:  if (dtp->u.p.advance_status == ADVANCE_NO ||
dtp->u.p.seen_dollar)
400:dtp->u.p.eor_condition = 1;

This is the unexpected behavior put forth in this thread.

The '$' feature of a format expression
affects only the end of output, like the
ADVANCE="NO" parameter to the WRITE statement.

So on repeated output, as produced by
multiple records given to a PRINT or WRITE
statement, there is still an unexpected
line break on each record except the last one.
(record is here a set of input values in the format expression)

Yet, in next_record_cc implemented in "transfer.c" (lines 3848 to 3870)
we find no regard of the dtp->u.p.seen_dollar setting
that would lead to the suppression of a Carriage Return,
as it might be expected when using the '$' feature in a format expression

3851:  static void
3852:  next_record_cc (st_parameter_dt *dtp)
3853:  {
...
3865:/* Output CR for the first character with default CC setting.  */
3866:*(p++) = dtp->u.p.cc.u.end;
3867:if (dtp->u.p.cc.len > 1)
3868:  *p = dtp->u.p.cc.u.end;
...
3870:  }

Conclusion:

It should be possible to patch the code here,
leading to a more convenient behavior for the
'$' format extension.

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-25 Thread max.pd at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #2 from max.pd at gmx dot de ---
(In reply to Dominique d'Humieres from comment #1)
> AFAIU $ fin format is a DEC(?) extension: see e.g.
> http://www.gf.uns.ac.rs/~hidro/download/CVF_LREF.PDF
> 
> Thi is not implemented in gfortran.

Well, so that is a non-Standard add-on to F77/F95.
I've found it in Visual Fortran (the link you sent)
and in Open Watcom Fortran (it's manual marks it as
non-standard, too).

Yet, the gfortran compiler seems to treat
the $-fin format the same way like an:
ADVANCE="NO" Parameter to a WRITE statement.

This implementation seems confusing to me.
For that it seems to work, as long as the
input fits to a single FORMAT expression.

[Bug libfortran/98825] Unexpected behavior of FORTRAN FORMAT expressions when suppressing new line with '$'

2021-01-25 Thread dominiq at lps dot ens.fr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

Dominique d'Humieres  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2021-01-25
 Status|UNCONFIRMED |WAITING

--- Comment #1 from Dominique d'Humieres  ---
AFAIU $ fin format is a DEC(?) extension: see e.g.
http://www.gf.uns.ac.rs/~hidro/download/CVF_LREF.PDF

Thi is not implemented in gfortran.