This is the system uname -a Linux argux9.fuqua.duke.edu 2.6.18-194.3.1.el5 #1 SMP Thu May 13 13:08:30 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
This is the compiler gfortran44 --version GNU Fortran (GCC) 4.4.0 20090514 (Red Hat 4.4.0-6) Copyright (C) 2009 Free Software Foundation, Inc. This is the problem The bug is that the mask is supposed to be applied before the statements within the where clause are evaluated. As can be seen from the output the statements within the mask are evaluated before the mask is applied. This is the relevant code do k = 1, rows + 1 if ( (k .gt. rows) .or. (k .gt. cols) ) then mask = .false. else mask = .true. end if where (mask) A = b(k) end where end do These are the compiler flags -save-temps -fbounds-check This is stderr At line 39 of file wherebug.F90 Fortran runtime error: Array reference out of bounds for array 'b', upper bound of dimension 1 exceeded (6 > 5) This is the -save-temps file a...@argux9$ cat wherebug.f90 # 1 "wherebug.F90" # 1 "<built-in>" # 1 "<command-line>" # 1 "wherebug.F90" program wherebug implicit none integer, parameter :: & stdin = 5, & ! reserved unit for standard input stdout = 6, & ! reserved unit for standard output stderr = 0 ! reserved unit for standard error integer, parameter :: & i1 = selected_int_kind(2), & i2 = selected_int_kind(4), & i4 = selected_int_kind(9), & i8 = selected_int_kind(18), & r4 = kind(1.0), & r8 = selected_real_kind(2*precision(1.0_r4)), & r16 = selected_real_kind(2*precision(1.0_r8)) integer, parameter :: rows = 5, cols = 5 integer :: i, j, k real(r8), dimension(rows,cols) :: A real(r8), dimension(rows) :: b logical, dimension(rows,cols) :: mask A = 1.0_r8 b = 1.0_r8 mask = .true. do k = 1, rows + 1 if ( (k .gt. rows) .or. (k .gt. cols) ) then mask = .false. else mask = .true. end if where (mask) A = b(k) end where end do end program wherebug -- Summary: where mask not applied before where clause evaluated Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: aronaldg at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45425