Fortran] Improved dependency analysis of pointer variables

Brooks Moses bmoses@stanford.edu
Thu Mar 16 08:21:00 GMT 2006


Toon Moene wrote:
>  > Of course, looking closer there
>  > couldn't possibly be a dependency using type-based aliasing, as Grid
>  > points to an array of integers and Y points to an array of reals.
> 
> But a far better argument would be that Y isn't a TARGET, and therefore 
> cannot be pointed to by *any* pointer.

Is that necessarily true?

For instance, the following code will associate a pointer with a 
variable that isn't a TARGET:

subroutine assoc(a,b)
   integer, pointer :: a
   integer, target :: b
   a => b
end subroutine
program notarget
   integer, pointer :: a
   integer :: b
   call assoc(a, b)
end program

This is a standard violation, I believe, as the standard says that 
objects without the TARGET attribute "shall not be associated with any 
accessible pointer".  However, I don't think this can reliably be tested 
for in all cases.

However, the whole point of TARGET is so that optimizations can be made 
easily for cases like this, so I think it's quite fair to _assume_ that 
Y is not pointed to by any pointer if it doesn't have the TARGET 
attribute -- and note that this may cause problems if one violates the 
standard by workarounds like the above.  (The proper phrase is "cannot 
be pointed to by any pointer in standard-conforming code," I suspect.)

- Brooks, going to go change some of my code that violates the standard 
this way, because until just now I'd assumed this was legal.



More information about the Gcc-patches mailing list