This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, fortran] Fix PR fortran/50050 breakage: ICE on valid with null pointer initialization


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.

Attachment: pr50050_backport.CL
Description: Text document

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;
 }
 

Attachment: pr50050_testsuite.CL
Description: Text document

! { dg-do compile }
!
! PR fortran/50050
! Out of bound whilst releasing initialization of allocate object
!
! Contributed by someone <sigurdkn@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 <abenson@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" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]