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] PR16206 - array initializers


On Sat, Jun 17, 2006 at 06:57:16AM +0200, Paul Thomas wrote:
> 2006-06-17  Paul Thomas  <pault@gcc.gnu.org>
> 
>    PR fortran/16206
>    * expr.c (find_array_element): Eliminate condition on length of
>    offset. Add bounds checking. Rearrange exit. Return try and
>    put gfc_constructor result as an argument.
>    (find_array_section): New function.
>    (find_substring_ref): New function.
>    (simplify_const_ref): Add calls to previous.
>    (gfc_simplify_expr): Only call gfc_expand_constructor for full
>    arrays.
> 
> 2006-06-17  Paul Thomas  <pault@gcc.gnu.org>
> 
>    PR fortran/16206
>    * gfortran.dg/array_initializer_1.f90: New test.
> 
> 

There a few minor questions/details to consider see below.

! 
!       /* Check the bounds.  */
!       if (ar->as->upper[i]
! 	    && (mpz_cmp (e->value.integer,
! 			ar->as->upper[i]->value.integer) > 0
! 	    || mpz_cmp (e->value.integer,
! 			ar->as->upper[i]->value.integer) > 0

These mpz_cmp appear to be redundant.

! 	    || mpz_cmp (e->value.integer,
! 			ar->as->lower[i]->value.integer) < 0
! 	    || mpz_cmp (e->value.integer,
! 			ar->as->lower[i]->value.integer) < 0))

These mpz_cmp appear to be redundant.

*************** remove_subobject_ref (gfc_expr * p, gfc_
*** 985,990 ****
--- 1008,1225 ----
  }
+   if (expr->shape == NULL)
+     expr->shape = gfc_get_shape (rank);
+ 
+   mpz_init_set_ui (delta_mpz, one);
+   mpz_init_set_ui (nelts, one);
+   mpz_init (tmp_mpz);
+ 
+   /* Build the counters to clock through the array reference.  */
+   for (idx = 0; idx < rank; idx++)
+     {
+       /* Make this stretch of code easier on the eye!  */
+       begin = ref->u.ar.start[idx];
+       finish = ref->u.ar.end[idx];
+       step = ref->u.ar.stride[idx];
+       lower = ref->u.ar.as->lower[idx];
+       upper = ref->u.ar.as->upper[idx];
+ 
+       if ((begin && begin->expr_type != EXPR_CONSTANT)
+ 	    || (finish && finish->expr_type != EXPR_CONSTANT)
+ 	    || (step && step->expr_type != EXPR_CONSTANT))
+ 	    return FAILURE;

Doesn't this "return FAILURE" leak memory?  Should you free at least the
mpz variables?

+ 	{
+ 	  gfc_error ("index in dimension %d is out of bounds "
+ 		     "at %L", idx + 1, &ref->u.ar.c_where[idx]);
+ 	  return FAILURE;

Again, is memory leaked here?


-- 
Steve


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