This reduced testcase is originally from the testsuite gfortran.dg/cray_pointers_2.f90. It generates an incorrect out-of-bounds error message when run with bounds-checking enabled. $ cat cray_pointers_2.f90 integer targ(2) integer pte pointer(ptr,pte(*)) ptr = loc(targ) targ(2) = -1 print *, pte(2) end $ gfortran -fbounds-check -fcray-pointer cray_pointers_2.f90 && ./a.out Fortran runtime error: Array reference out of bounds
Confirmed.
Subject: Bug number PR 27786 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-05/msg01544.html
Subject: Bug 27786 Author: langton Date: Thu Jun 8 21:00:26 2006 New Revision: 114495 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114495 Log: * cray_pointers_2.f90: Add -fbounds-check compile flag. PR fortran/27786 * trans-array.c (gfc_conv_array_ref): Eliminate bounds checking for assumed-size Cray pointees. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-array.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/cray_pointers_2.f90
I've committed a patch that should fix this bug.
I'm reopening the PR because the bug is not fixed yet on the 4.1 branch. The current policy is to allow a week before comitting your patch to 4.1 (after bootstrap & regtesting), and then close the bugzilla PR. (in case you need info on how to use svn to backport a patch, you can read http://gcc.gnu.org/wiki/SvnMerge)
Subject: Bug 27786 Author: langton Date: Thu Jun 15 23:07:14 2006 New Revision: 114692 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114692 Log: PR fortran/27786 * cray_pointers_2.f90: Add -fbounds-check compile flag. PR fortran/27786 * trans-array.c (gfc_conv_array_ref): Eliminate bounds checking for assumed-size Cray pointees. Modified: branches/gcc-4_1-branch/gcc/fortran/ChangeLog branches/gcc-4_1-branch/gcc/fortran/trans-array.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/cray_pointers_2.f90
I've backported the patch to 4.1, so this bug should be resolved.