[Patch, Fortran] Add parsing support for assumed-rank array

Tobias Burnus burnus@net-b.de
Thu Jul 19 21:36:00 GMT 2012


Am 19.07.2012 17:55, schrieb Mikael Morin:
> Maybe add: gcc_assert (from->rank != -1 || to->corank == 0); 
> Access to lower and upper bounds is OK, but again maybe we could just 
> assert here. 

I will add the asserts – and undo the patch.

> s/deferred rank/assumed rank/ ? 

Of course. Well spotted!

>> -		  if (fsym && e->expr_type != EXPR_NULL
>> +		  /* Wrap scalar variable in a descriptor. We need to convert
>> +		     the address of a pointer back to the pointer itself before,
>> +		     we can assign it to the data field.  */
>> +		
>> +		  if (fsym && fsym->as && fsym->as->type == AS_ASSUMED_RANK
>> +		      && fsym->ts.type != BT_CLASS && e->expr_type != EXPR_NULL)
>> +		    {
>> +		      tmp = parmse.expr;
>> +		      if (TREE_CODE (tmp) == ADDR_EXPR
>> +			  && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (tmp, 0))))
> This looks fragile. If you have {tmp = &ptr; value = tmp;} instead of
> {value = &ptr;} it doesn't work anymore.
> You can rely on fsym->attr.{pointer,allocatable,...) instead, or can't you?

No, I cannot if I use "if (attr.pointer)" I exactly run into the problem 
I want to avoid: Taking the address of the temporary variable, which I 
don't want. (Well, actually via TREE_OPERAND, I won't: I get an ICE.)

However, with the current code, I get:

     D.1874 = f ();
     desc.0.dtype = 600;
     desc.0.data = (void *) D.1874;
     sub (&desc.0);
     D.1874 = (integer(kind=4) *) desc.0.data;

which looks fine.

Thus, I intent to keep my version.

>> Mikael Morin wrote:
>>> What about naming the flag in_actual_arg and moving the
>>> inquiry_argument condition to the error condition?
> I didn't mean changing the semantics.
>
> I attach a patch showing what I had in mind. I think it is equivalent;
> it passes your assumed rank testcases at least. As a cherry on the cake,
> it brings a small diagnostic improvement regarding assumed type/rank and
> inquiry functions. Let's hope you like the wording.
> As second attachment, there is a patch restoring the flags in case of
> failure, as that was making me uncomfortable.
>
> I'm regression testing them, and if they work and are fine to you, let's
> go with these patches.

I will now regtest everything, read through the whole patch – your part 
and mine, update the ChangeLog and commit it tomorrow.

Thanks for the review!

Tobias



More information about the Gcc-patches mailing list