Created attachment 42061 [details] Source file of dtio_bug_1.f90 Many tests of the DTIO feature (in .../gcc/testsuite/gfortran.dg/dtio_*.f90) use inline format like in: write( unit=10, fmt="(DT'zeroth')", iostat=myiostat, iomsg=astring) member When I attempted to put the DTIO format string "(DT'zeroth')" in a character string, I got many kinds of error, from ICE (Internal Compiler Error) to bad execution. See the attached file (which comes from the Gfortran testsuite dtio_1.f90, simplified as much as possible) : dtio_bug_1.f90 According the length of the character string, it may lead to some errors. I think the bug is related to how is read the DTIO format string. The bug occurs either from GCC-7.2 compiled by myself on Ubuntu-16.10, either from GCC-7.2 packaged in Ubuntu-17.10. Regards, Édouard
I omit to say that many lines in the attached source are commented by a double bang (!!); remove some of them to reveal the bug... EC
I am investigating. Thanks for report
Confirmed.
With gfortran 7.2.1 and trunk, I do not see the error from the write at line 46: write( unit=10, fmt=fmt_str, iostat=myiostat, iomsg=astring) member I do see the ICE with this one: write( unit=10, fmt=trim(fmt_str), iostat=myiostat, iomsg=astring) member
The ice is because we are not handling the case where the expreesion is type function vs character expression or character constant. I am thinking we need to simplify the expression before trying to use it.
Created attachment 42992 [details] A peliminary patch The attached patch allows the test cases to compile and run. Remaining is to formulate what checks we really do want to do at compile time and what to do for run time. For example, if a user has provided DTIO procedures, but the format statement does not contain a 'DT' specifier, what do we do? If the format string is in a variable, the situation can only be checked at run time.
Author: jvdelisle Date: Sat Jan 13 20:41:00 2018 New Revision: 256649 URL: https://gcc.gnu.org/viewcvs?rev=256649&root=gcc&view=rev Log: 2018-01-13 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/82007 * resolve.c (resolve_transfer): Delete code looking for 'DT' format specifiers in format strings. Set formatted to true if a format string or format label is present. * trans-io.c (get_dtio_proc): Likewise. (transfer_expr): Fix whitespace. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/fortran/trans-io.c
Should I backport this to 7?
> Should I backport this to 7? IMO yes.
Author: jvdelisle Date: Tue Feb 20 04:05:38 2018 New Revision: 257837 URL: https://gcc.gnu.org/viewcvs?rev=257837&root=gcc&view=rev Log: 2018-02-19 Jerry DeLisle <jvdelisle@gcc.gnu.org> Backport from trunk PR fortran/82007 * resolve.c (resolve_transfer): Delete code looking for 'DT' format specifiers in format strings. Set formatted to true if a format string or format label is present. * trans-io.c (get_dtio_proc): Likewise. (transfer_expr): Fix whitespace. Modified: branches/gcc-7-branch/gcc/fortran/ChangeLog branches/gcc-7-branch/gcc/fortran/resolve.c branches/gcc-7-branch/gcc/fortran/trans-io.c
Fixed on 7 and closing.