[patch, Fortran] Fix PR 66041

Thomas Koenig tkoenig@netcologne.de
Sat May 9 22:31:00 GMT 2015


Am 09.05.2015 um 13:59 schrieb Mikael Morin:

> You also need to remove/free the trailing subreferences.

That's right, I did that.  Although I will probably never understand
why lbound(a) should be different from lbound(a%r)...

>> +		      /* 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.

It doesn't (for whatever reason), so I kept on setting it.

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

It will be part of the lbound expression, or be simplified away.

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

Changed.

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

Done (all in once).

I have attached the new patch (in which I also restructured the test),
plus the test cases.

OK for trunk?

	Thomas

2015-05-08  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/66041
        * frontend-passes.c (scalarized_expr): Copy first argument so it
        is not necessary to call gfc_copy_expr() on its argument.  Set
        correct dimension and shape for the expression to be passed to
        lbound. Remove trailing references after array refrence.
        (inline_matmul_assign):  Remove gfc_copy_expr() from calls
        to scalarized_expr().

2015-05-08  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/66041
        * gfortran.dg/inline_matmul_7.f90:  New test.
        * gfortran.dg/inline_matmul_8.f90:  New test.
        * gfortran.dg/inline_matmul_9.f90:  New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p5.diff
Type: text/x-patch
Size: 4119 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150509/c878781a/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inline_matmul_7.f90
Type: text/x-fortran
Size: 997 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150509/c878781a/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inline_matmul_8.f90
Type: text/x-fortran
Size: 544 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150509/c878781a/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inline_matmul_9.f90
Type: text/x-fortran
Size: 710 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150509/c878781a/attachment-0003.bin>


More information about the Fortran mailing list