*ping* [patch, fortran, 4.9] Dependency and string length calculation improvements

Tobias Burnus burnus@net-b.de
Thu Mar 28 17:48:00 GMT 2013


Thomas Koenig wrote:
> below is a patch which improves dependency checking for array
> assignments and calculation of string lengths. 

Talking about dependencies, I wonder whether you would be interested 
implementing the function
    bool gfc_simply_noncontiguous (gfc_expr *);
or something similarly named.

It should return true, if the expression is known to be noncontiguous. 
Such a function has many uses:
- Diagnostic to reject invalid code such as "contiguous_ptr => 
noncontiguous_target",* passing a noncontiguous expression to c_loc, and 
possibly more
- Compile-time simplification for the IS_CONTIGUOUS intrinsic (not yet 
implemented)
- If we pass a noncontiguous array to a contiguous dummy argument (i.e. 
assumed-size, explicit-size or contiguous attribute), there is the check 
if(new_array != old_array) { unpack(old_array,new_array);free(new_array) 
}. If one knows that the array is noncontiguous, the 
"if(new_array!=old_array) check could be removed (missed optimization)
- Potentially some more uses

Additionally, gfc_simply_noncontiguous has some bugs (both false 
positive and false negative) - especially for BT_CLASS and for 
ref-array/ref-substring handling (esp. when combined).

Actually, for
   type t
     integer i
   end type t
type(t) :: foo(5)
is_contiguous(foo(:)%i), it depends on the aligning. (I think one needs 
to call gfc_target_expr_size for "foo(:)" and compare it with the 
storage size of foo(1)%i.) Of course, if there multiple components, 
foo(:)%i is obviously noncontiguous. (For gfc_simply_contiguous, see the 
Fortran standard for the exact definition of "simply contiguous", which 
should be used with strict==true).


If you will work on it, please tell me - otherwise, I might start to 
work on it. (It is not on top of my agenda, but for Fortran 2008's 
IS_CONTIGUOUS() and for diagnostic reasons, I like to have it.)


  * * *


But now, a bit belated, to your patch.

On 25.03.2013 16:43, Thomas Koenig wrote:
> OK for trunk?

OK - except for the following three minor coding convention nits.


> +}
> +/* Return the difference between two expressions.  Integer expressions of

Two empty lines before the comment.

> +}
> +
>   /* Returns 1 if the two ranges are the same and 0 if they are not (or if the

This time only one empty line is missing.

> -      mpz_clear (tmp);
> +      mpz_clear (tmp); /* gfc_dep_difference returned true, so tmp was initialized.  */

I am not sure whether the comment is needed - but if you want to keep 
it: The line is too long ;-)


Tobias

* Example for that
pointer, contiguous :: ptr
target :: tgt(5)
ptr => tgt(::2)



More information about the Fortran mailing list