diff mbox

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

Message ID 201109011635.45901.mikael.morin@sfr.fr
State New
Headers show

Commit Message

Mikael Morin Sept. 1, 2011, 2:35 p.m. UTC
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.morin@gcc.gnu.org>

	* resolve.c (gfc_expr_to_initialize): Don't copy rank.
	Free copied shape.  Recalculate shape and rank.
2011-09-01  Mikael Morin  <mikael.morin@gcc.gnu.org>

	* gfortran.dg/alloc_comp_initializer_3.f90: New test.
	* gfortran.dg/pointer_comp_init.f90: New test.
diff mbox

Patch

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