https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128682
Bug ID: 128682
Summary: ICE in gfc_get_expr_charlen with transpose(reshape())
of character implied-do array constructor as actual
argument
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: fredjones42 at proton dot me
Target Milestone: ---
The following valid program gives an ICE with every version I tested, from
4.9.4 through trunk 20261112 (x86_64-linux-gnu, via Compiler Explorer). It also
fails with the MSYS2 ucrt64 build of 16.2.0 on Windows 11. It is not a
regression.
program p
implicit none(type, external)
character(len=6) :: blk = 'ab#.#.'
integer :: i
integer, parameter :: w = 2, h = 3
call show(transpose(reshape([(blk(i:i), i=1, len(blk))], [w, h])))
contains
subroutine show(g)
character, intent(in) :: g(:, :)
print '(a)', g
end subroutine show
end program p
$ gfortran -Wall -Wextra ice.f90
ice.f90:6:70:
6 | call show(transpose(reshape([(blk(i:i), i=1, len(blk))], [w, h])))
| 1
internal compiler error: in gfc_get_expr_charlen, at fortran/trans-expr.cc:2295
0x288c9d8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2880e0b internal_error(char const*, ...)
???:0
0xa80a08 fancy_abort(char const*, int, char const*)
???:0
0xbf42d2 gfc_conv_expr_descriptor(gfc_se*, gfc_expr*)
???:0
0xbf54c7 gfc_conv_array_parameter(gfc_se*, gfc_expr*, bool, gfc_symbol const*,
char const*, tree_node**, tree_node**, tree_node**)
???:0
0xc1e5e1 gfc_conv_procedure_call(gfc_se*, gfc_symbol*, gfc_actual_arglist*,
gfc_expr*, vec<tree_node*, va_gc, vl_embed>*)
???:0
0xc8d2b8 gfc_trans_call(gfc_code*, bool, tree_node*, tree_node*, bool)
???:0
0xc11e93 gfc_generate_function_code(gfc_namespace*)
???:0
0xb6e86e gfc_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
No warnings are issued before the ICE. Optimization level makes no difference
(same ICE at -O0, -O1, -O2, -O3 and -Os on trunk and 16.2.0).
Narrowing:
- reshape([(blk(i:i), i=1, len(blk))], [w, h]) without transpose: compiles.
- transpose(reshape(['a','b','c','d','e','f'], [w, h])) with literals instead
of the implied-do: compiles.
- Adding a type-spec, [character :: (blk(i:i), i=1, len(blk))]: still ICEs.
So the trigger is transpose of a reshape of a character array constructor with
an implied-do of substrings, passed as an actual argument to an assumed-shape
dummy.
Workaround: assign the reshape result to a variable first.
Same assert in older versions (line numbers in trans-expr.c / trans-expr.cc):
4.9.4: 1393 5.5: 1678 6.3: 1789 7.3: 1767 8.5: 1828 9.4: 2028
10.5: 2035 11.4: 2087 12.5: 2129 13.4: 2167 14.3: 2205 15.2: 2290
16.2: 2387 trunk: 2295
(For versions before 8, "implicit none(type, external)" was replaced by
"implicit none".)
$ gfortran -v
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-snapshot/bin/gfortran
Target: x86_64-linux-gnu
Configured with: ../gcc-trunk-20261112/configure
--prefix=/opt/compiler-explorer/gcc-build/staging --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap
--enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --enable-clocale=gnu
--enable-languages=c,c++,fortran,ada,objc,obj-c++,go,d,rust,m2,cobol,algol68
--enable-ld=yes --enable-gold=yes --enable-libstdcxx-time=yes
--enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix
--with-pkgversion=Compiler-Explorer-Build-gcc-695282a69cfca0f730f77be3bf504dabc790c3a7-binutils-2.47
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20261112 (experimental)
(Compiler-Explorer-Build-gcc-695282a69cfca0f730f77be3bf504dabc790c3a7-binutils-2.47)