https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126777
Bug ID: 126777
Summary: IMAGE_INDEX intrinsic incorrectly implements team
forms
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: dobonachea at lbl dot gov
CC: damian at archaeologic dot codes
Target Milestone: ---
Created attachment 65287
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65287&action=edit
Fortran source code testing IMAGE_INDEX with team arguments
gfortran 16.2.0 fails to correctly implement the team forms of the IMAGE_INDEX
intrinsic.
F2023 specifies:
> 16.9.107 IMAGE_INDEX (COARRAY, SUB) or (COARRAY, SUB, TEAM)
> or (COARRAY, SUB, TEAM_NUMBER)
> ...
> Arguments.
> ...
> TEAM shall be a scalar of type TEAM_TYPE from the intrinsic module
> ISO_FORTRAN_ENV, with a value that identifies the current
> or an ancestor team.
> TEAM_NUMBER shall be an integer scalar. It shall identify the
> initial team or a sibling team of the current team.
These team arguments were added in Fortran 2018.
Demonstration:
---------------------------------------------------------
cgpu$ cat image_index.F90
program test_image_index
use iso_fortran_env
implicit none
integer :: my_coarray[*]
integer :: res(3)
if (this_image() == 1) then
! image_index works without teams:
res(1) = image_index(my_coarray, [num_images()]) ! works
#if KEYWORD
! keyword arguments are not correctly implemented:
res(2) = image_index(my_coarray, [num_images()], TEAM=GET_TEAM())
res(3) = image_index(my_coarray, [num_images()], TEAM_NUMBER=TEAM_NUMBER())
#else
! omitting the keyword leads to a compiler crash:
res(2) = image_index(my_coarray, [num_images()], GET_TEAM()) ! ICE
res(3) = image_index(my_coarray, [num_images()], TEAM_NUMBER()) ! ICE
#endif
print *, "Total images running: ", num_images()
print *, "------------------------------------------------"
print *, "IMAGE_INDEX for cosubscript [", num_images(), "] : ", res
end if
end program test_image_index
cgpu$ gfortran --version
GNU Fortran (GCC) 16.2.0
Copyright (C) 2026 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.
cgpu$ gfortran -DKEYWORD=1 -c -fcoarray=lib image_index.F90
image_index.F90:15:13:
15 | res(2) = image_index(my_coarray, [num_images()], TEAM=GET_TEAM()) !
missing keyword
| 1
Error: Cannot find keyword named 'team' in call to 'image_index' at (1)
image_index.F90:16:13:
16 | res(3) = image_index(my_coarray, [num_images()],
TEAM_NUMBER=TEAM_NUMBER()) ! missing keyword
| 1
Error: Cannot find keyword named 'team_number' in call to 'image_index' at (1)
cgpu$ gfortran -DKEYWORD=0 -c -fcoarray=lib image_index.F90
image_index.F90:19:70:
19 | res(2) = image_index(my_coarray, [num_images()], GET_TEAM()) ! ICE
| 1
internal compiler error: in walk_coarray, at fortran/trans-array.cc:8380
0x2a15e4d internal_error(char const*, ...)
../../src/gcc/diagnostic-global-context.cc:787
0x7912ad fancy_abort(char const*, int, char const*)
../../src/gcc/diagnostics/context.cc:1813
0x982eec walk_coarray
../../src/gcc/fortran/trans-array.cc:8380
0x982eec gfc_conv_expr_descriptor(gfc_se*, gfc_expr*)
../../src/gcc/fortran/trans-array.cc:8485
0x9e45b1 trans_image_index
../../src/gcc/fortran/trans-intrinsic.cc:2154
0x9db397 gfc_trans_assignment_1
../../src/gcc/fortran/trans-expr.cc:13424
0x9632ac gfc_trans_assign(gfc_code*)
../../src/gcc/fortran/trans-expr.cc:13878
0x9632ac trans_code
../../src/gcc/fortran/trans.cc:2363
0xa4106d gfc_trans_code(gfc_code*)
../../src/gcc/fortran/trans.cc:2727
0xa4106d gfc_trans_if_1
../../src/gcc/fortran/trans-stmt.cc:1619
0xa41a2b gfc_trans_if(gfc_code*)
../../src/gcc/fortran/trans-stmt.cc:1651
0x963227 trans_code
../../src/gcc/fortran/trans.cc:2455
0x9b63e6 gfc_trans_code(gfc_code*)
../../src/gcc/fortran/trans.cc:2727
0x9b63e6 gfc_generate_function_code(gfc_namespace*)
../../src/gcc/fortran/trans-decl.cc:8322
0x8c51a2 gfc_generate_code(gfc_namespace*)
../../src/gcc/fortran/trans.cc:2744
0x8c51a2 translate_all_program_units
../../src/gcc/fortran/parse.cc:7627
0x8c51a2 gfc_parse_file()
../../src/gcc/fortran/parse.cc:7957
0x958aca gfc_be_parse_file
../../src/gcc/fortran/f95-lang.cc:247
/usr/local/pkg/gcc/16.2.0/libexec/gcc/x86_64-pc-linux-gnu/16.2.0/f951
image_index.F90 -cpp=/tmp/cc0VO9Uv.fii -quiet -imultiarch x86_64-linux-gnu -D
KEYWORD=0 image_index.F90 -quiet -dumpbase image_index.F90 -dumpbase-ext .F90
-mtune=generic -march=x86-64 -fcoarray=lib -fintrinsic-modules-path
/usr/local/pkg/gcc/16.2.0/lib/gcc/x86_64-pc-linux-gnu/16.2.0/finclude
-fpre-include=/usr/include/finclude/x86_64-linux-gnu/math-vector-fortran.h -o
/tmp/ccF1dxna.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
---------------------------------------------------------
Here is the correct answer, from NAG 7.2:
headroom$ nagfor -coarray -DKEYWORD=1 image_index.F90 && env
NAGFORTRAN_NUM_IMAGES=4 a.out
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7238
[NAG Fortran Compiler normal termination]
Total images running: 4
------------------------------------------------
IMAGE_INDEX for cosubscript [ 4 ] : 4 4 4
headroom$ nagfor -coarray -DKEYWORD=0 image_index.F90 && env
NAGFORTRAN_NUM_IMAGES=4 a.out
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7238
[NAG Fortran Compiler normal termination]
Total images running: 4
------------------------------------------------
IMAGE_INDEX for cosubscript [ 4 ] : 4 4 4