[Bug fortran/93762] New: Truncation of deferred-length string when passing as optional
chaudhry.ross at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Feb 15 20:38:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93762
Bug ID: 93762
Summary: Truncation of deferred-length string when passing as
optional
Product: gcc
Version: 8.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: chaudhry.ross at gmail dot com
Target Milestone: ---
Created attachment 47848
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47848&action=edit
Minimal reproducing code
(This issue was first reported on SO here:
https://stackoverflow.com/questions/60229805/truncation-of-deferred-length-string-when-passing-as-optional)
When passing strings declared as deferred-length and optional through several
subroutines, they are truncated. A minimal example is attached, which yields
the following (expected) result on Intel 16.0, Intel 2019_U4, or PGI 15.10:
$ ifort main.f90 && ./a.out
at bot of deepest_call, str is "12345"
at bot of interface_call, str is "12345"
at bot of main, str is "12345"
However, with gfortran 4.8.5:
$ gfortran --version
GNU Fortran (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
Copyright (C) 2015 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
$ gfortran main.f90 && ./a.out
at bot of deepest_call, str is "12345"
at bot of interface_call, str is ""
at bot of main, str is ""
On the newer version of gfortran I have available (7.2 and 8.2.0), this simple
example segfaults when compiled with no options, but truncates the output when
compiled using checks:
$ gfortran --version
GNU Fortran (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gfortran -g -fbacktrace -Wall -Wextra -std=f2008 -fcheck=all -Og main.f90 &&
./a.out
at bot of deepest_call, str is "12345"
at bot of interface_call, str is ""
at bot of main, str is ""
It seems to me that this is a compiler error spanning a range of GCC versions
(at least 4.8.5 to 8.2.0). So my first purpose for reporting it here is so
people are aware of it.
According to francescalus on the StackOverflow post, the error does not occur
on the very latest 10.0.0. However, I think it would be good to add this
minimal example (or something similar) to the gfortran test suite to prevent
the error from occurring again.
More information about the Gcc-bugs
mailing list