[patch, Fortran] Fix PR 66041

Mikael Morin mikael.morin@sfr.fr
Sat May 9 11:59:00 GMT 2015


Hello,

Le 09/05/2015 00:11, Thomas Koenig a écrit :
> Index: frontend-passes.c
> ===================================================================
> --- frontend-passes.c	(Revision 222864)
> +++ frontend-passes.c	(Arbeitskopie)
> @@ -2611,14 +2611,40 @@ scalarized_expr (gfc_expr *e_in, gfc_expr **index,
>  		    {
>  		      /* Look at full individual sections, like a(:).  The first index
>  			 is the lbound of a full ref.  */
> -
> +		      int j;
>  		      gfc_array_ref *ar;
> +		      gfc_expr *lbound_e;
>  
> -		      ar = gfc_find_array_ref (e_in);
> +		      lbound_e = gfc_copy_expr (e_in);
> +		      ar = gfc_find_array_ref (lbound_e);
> +
>  		      ar->type = AR_FULL;
> +		      for (j = 0; j < ar->dimen; j++)
> +			{
> +			  gfc_free_expr (ar->start[j]);
> +			  ar->start[j] = NULL;
> +			  gfc_free_expr (ar->end[j]);
> +			  ar->end[j] = NULL;
> +			  gfc_free_expr (ar->stride[j]);
> +			  ar->stride[j] = NULL;
> +			}
> +
You also need to remove/free the trailing subreferences.

> +		      /* We have to get rid of the shape, if thre is one.  Do
> +			 so by freeing it and calling gfc_resolve to rebuild it,
> +			 if necessary.  */
> +			 
> +		      if (lbound_e->shape)
> +			gfc_free_shape (&(lbound_e->shape), lbound_e->rank);
> +

> +		      lbound_e->rank = ar->dimen;
ar->dimen is  not what you think it is.
It is 3 for array(1, 1, :), while the rank is 1.
gfc_resolve_expr should set the rank for you, so just remove this line.

> +			
> +		      gfc_resolve_expr (lbound_e);
> +		      lbound = get_array_inq_function (GFC_ISYM_LBOUND,
> +						       lbound_e, i + 1);
free lbound_e?

>  		    }
> -		  lbound = get_array_inq_function (GFC_ISYM_LBOUND, e_in,
> -						   i_index + 1);
> +		  else
> +		    lbound = get_array_inq_function (GFC_ISYM_LBOUND, e_in,
> +						     i_index + 1);
You can't reuse e_in if it has subreferences.

One suggestion: you may want to move all the above to a function
extracting the full array.

>  		}
>  	      
>  	      ar->dimen_type[i] = DIMEN_ELEMENT;
> @@ -2639,6 +2665,8 @@ scalarized_expr (gfc_expr *e_in, gfc_expr **index,
>  	  i_index ++;
>  	}
>      }
> +  gfc_free_expr (e_in);
> +
This side effect is asking for trouble.
Instead of this, remove the copies made in the callers.
This is independant from the rest, so it can be made later as a follow-up.

>    return e;
>  }
>  
> 

I attach a variant of your inline_matmul_8.f90 that is not working yet
because of subreferences.

Mikael



-------------- next part --------------
A non-text attachment was scrubbed...
Name: inline_matmul_8.f90.diff
Type: text/x-patch
Size: 840 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20150509/74203369/attachment.bin>


More information about the Gcc-patches mailing list