A user reported that the gfortran compiler failed to compile the cesm/ccsm pop2 hmix_gm.F90 module, because it detected an array-bounds violation.
The user then contacted the gfortran developers, who confirmed that the gfortran compiler was incorrect. The gfortran internal bug report follows. (Note that the spacing/formatting of the original message is not preserved)
Date: Fri, Aug 27, 2010 at 7:58 AM
Subject: [Bug fortran/45425] Bounds check applied before MASK of WHERE construct
------- Comment #1 2010-08-27 11:58 -------
Confirm, the bounds checks are misplaces. Simplified test case:
implicit none
integer :: A(1), i,b(1)
logical :: mask(1)
mask = .false.
b = 5
do i = 2, 2
where (mask)
A = b(i)
end where
end do
end
If one looks at the dump of the internal representation (-fdump-tree-original)
one sees that WHERE itself is properly handled - only the bounds check is
outside of the WHERE loop and thus outside of the MASK:
if (__builtin_expect (i 1) goto L.4;
if (mask[S.1 + -1])
{
a[S.1 + -1] = b[i + -1];
}
S.1 = S.1 + 1;
}
What |Removed |Added
----------------------------------------------------------------------------
OtherBugsDependingOnThis| *|27766
Keywords| |wrong-code
Known to fail| |4.1.2 4.6.0
* * * * * *Summary|where mask not applied * * *|Bounds check applied before
|before where clause * * * * |MASK of WHERE construct
|evaluated * * * * * * * * * |
The user then contacted the gfortran developers, who confirmed that the gfortran compiler was incorrect. The gfortran internal bug report follows. (Note that the spacing/formatting of the original message is not preserved)
Date: Fri, Aug 27, 2010 at 7:58 AM
Subject: [Bug fortran/45425] Bounds check applied before MASK of WHERE construct
------- Comment #1 2010-08-27 11:58 -------
Confirm, the bounds checks are misplaces. Simplified test case:
implicit none
integer :: A(1), i,b(1)
logical :: mask(1)
mask = .false.
b = 5
do i = 2, 2
where (mask)
A = b(i)
end where
end do
end
If one looks at the dump of the internal representation (-fdump-tree-original)
one sees that WHERE itself is properly handled - only the bounds check is
outside of the WHERE loop and thus outside of the MASK:
if (__builtin_expect (i 1) goto L.4;
if (mask[S.1 + -1])
{
a[S.1 + -1] = b[i + -1];
}
S.1 = S.1 + 1;
}
What |Removed |Added
----------------------------------------------------------------------------
OtherBugsDependingOnThis| *|27766
Keywords| |wrong-code
Known to fail| |4.1.2 4.6.0
* * * * * *Summary|where mask not applied * * *|Bounds check applied before
|before where clause * * * * |MASK of WHERE construct
|evaluated * * * * * * * * * |