This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/43331] New: Cray pointers generate bogus IL for the middle-end
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Mar 2010 12:10:46 -0000
- Subject: [Bug fortran/43331] New: Cray pointers generate bogus IL for the middle-end
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I have a patch that exposes this and causes a "miscompile" of
gfortran.dg/cray_pointers_2.f90. Reduced testcase:
! { dg-do run }
! { dg-options "-fcray-pointer -fbounds-check" }
! Series of routines for testing a Cray pointer implementation
program craytest
call ptr5
end program craytest
subroutine ptr5
logical :: intne
integer :: i
integer, parameter :: n = 9
integer itarg1 (n)
integer ipte1 (*)
pointer(iptr4,ipte1)
iptr4 = loc(itarg1)
do, i=1,n
ipte1(i) = i
if (intne(ipte1(i), itarg1(i))) then
! Error #143
call abort()
endif
end do
end subroutine ptr5
! Separate function calls to break Cray pointer-indifferent optimization
logical function intne(ii,jj)
integer :: i,j
intne = ii.ne.jj
if (intne) then
write (*,*) ii," doesn't equal ",jj
endif
end function intne
where we can see the following IL created by the FE:
ptr5 ()
{
integer(kind=4) i;
integer(kind=8) iptr4;
integer(kind=4) ipte1[1] [value-expr: *(integer(kind=4)[1] *) iptr4];
integer(kind=4) itarg1[9];
{
integer(kind=8) D.1548;
D.1548 = (integer(kind=8)) &itarg1;
iptr4 = D.1548;
}
...
ipte1[NON_LVALUE_EXPR <SAVE_EXPR <(integer(kind=8)) i>> + -1] = i;
...
if (intne (&ipte1[NON_LVALUE_EXPR <SAVE_EXPR <(integer(kind=8)) i>>
+ -1], &itarg1[NON_LVALUE_EXPR <SAVE_EXPR <(integer(kind=8)) i>> + -1]))
you can clearly see that substituting the value-expr
*(integer(kind=4)[1] *) iptr4 for ipte1 will expose an array size of 1 (!)
to the middle-end, which it will happily oblige to and optimize
&ipte1[i - 1] to &ipte1[0].
If the array size is not known the FE should generate
*(integer(kind=4)[] *) iptr4
--
Summary: Cray pointers generate bogus IL for the middle-end
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rguenth at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43331