https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81095
Bug ID: 81095
Summary: fcheck=bounds and empty forall
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: guez at lmd dot ens.fr
Target Milestone: ---
$ uname -a
Linux curie91 2.6.32-642.15.1.el6.Bull.110.x86_64 #1 SMP Wed Mar 1 14:13:44 CET
2017 x86_64 x86_64 x86_64 GNU/Linux
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/ccc/products2/gcc-7.1.0/BullEL_6__x86_64/default/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran --enable-lto
--enable-checking=release --disable-multilib --enable-shared=yes
--enable-static=yes --enable-threads=posix --enable-gold=default
--enable-plugins --enable-ld --with-plugin-ld=ld.gold --enable-bootstrap
--prefix=/ccc/products/gcc-7.1.0/default
--with-local-prefix=/ccc/products/gcc-7.1.0/default
Thread model: posix
gcc version 7.1.0 (GCC)
$ gfortran --version
GNU Fortran (GCC) 7.1.0
Here is the test program:
$ cat test_empty_forall.f
program test_empty_forall
implicit none
integer contours(0)
integer a(10, 10)
integer i, j
forall (i = 1:size(contours))
forall (j = 1:contours(i)) a(i, j) = i + j
end forall
end program test_empty_forall
$ gfortran -ffree-form -fcheck=bounds test_empty_forall.f
$ ./a.out
At line 7 of file test_empty_forall.f
Fortran runtime error: Index '0' of dimension 1 of array 'contours' below lower
bound of 1
Error termination. Backtrace:
#0 0x4006da in ???
#1 0x40081f in ???
#2 0x2b61c2fabd1c in ???
#3 0x400588 in ???
This is wrong. There is no error. As size(contours) is 0, the set of values for
i is empty and the body of the outer forall should not be executed. Cf. Adams
(2009, "Fortran 2003 Handbook", ยง 7.5.7.2, page 253).