On Wednesday 24 August 2011 10:58:19 Tobias Burnus wrote: > On 08/24/2011 12:01 AM, Mikael Morin wrote: > > this is an attempt to fix my recent breakage for PR50050. > > I forgot that shape can't always be known, and thus, that for some > > expressions, the shape field is a NULL pointer. > > > > Neither bootstraped, nor regression tested, but it is in progress. My > > machine does its best (which is not a lot) to have this properly > > compiled and tested (and then committed) as soon as possible. > > Otherwise OK for 4.{4..7} ? > > OK for 4.6 and 4.7 (after regtesting). > > As 4.4 and 4.5 are not affected by this regression and only by the > original bug (comment 0 of PR 50050), please wait a while before > committing the combined patch to older branches. (One could also > consider whether having 50050c0 fixed on 4.6/4.7 is sufficient.) > > Tobias
Hello, Despite your call for less non-regression backports, I'm going to use the following (slightly less intrusive) variant for 4.5 and 4.4. I can't stand knowing this bug exists in the wild. Mikael PS: the testcase alloc_comp_initializer_3.f90 doesn't trigger on 4.5, so this patch fixes a silent memory out of bound (instead of an ICE). I add the testcase anyway, in case it could trigger on some targets.
2011-09-01 Mikael Morin <mikael.mo...@gcc.gnu.org> * resolve.c (gfc_expr_to_initialize): Don't copy rank. Free copied shape. Recalculate shape and rank.
Index: resolve.c =================================================================== --- resolve.c (révision 178386) +++ resolve.c (copie de travail) @@ -6172,10 +6172,19 @@ gfc_expr_to_initialize (gfc_expr *e) for (i = 0; i < ref->u.ar.dimen; i++) ref->u.ar.start[i] = ref->u.ar.end[i] = ref->u.ar.stride[i] = NULL; - result->rank = ref->u.ar.dimen; break; } + if (result->shape != NULL) + { + for (i = 0; i < result->rank; i++) + mpz_clear (result->shape[i]); + gfc_free (result->shape); + result->shape = NULL; + } + + /* Recalculate rank, shape, etc. */ + gfc_resolve_expr (result); return result; }
2011-09-01 Mikael Morin <mikael.mo...@gcc.gnu.org> * gfortran.dg/alloc_comp_initializer_3.f90: New test. * gfortran.dg/pointer_comp_init.f90: New test.
! { dg-do compile } ! ! PR fortran/50050 ! Out of bound whilst releasing initialization of allocate object ! ! Contributed by someone <sigur...@gmail.com> program bug implicit none type foo integer, pointer :: a => null() end type type(foo), dimension(:,:), allocatable :: data allocate(data(1:1,1)) ! This used to lead to an ICE end program
! { dg-do compile } ! ! PR fortran/50050 ! ICE whilst trying to access NULL shape. ! Reduced from the FoX library http://www1.gly.bris.ac.uk/~walker/FoX/ ! Contributed by Andrew Benson <aben...@its.caltech.edu> module m_common_attrs implicit none type dict_item end type dict_item type dict_item_ptr type(dict_item), pointer :: d => null() end type dict_item_ptr contains subroutine add_item_to_dict() type(dict_item_ptr), pointer :: tempList(:) integer :: n allocate(tempList(0:n+1)) end subroutine add_item_to_dict end module m_common_attrs ! { dg-final { cleanup-modules "m_common_attrs" } }