Alan:
The example you give
In the calling routine:
CALL sub( ..., a, a)
The called subroutine started:
SUBROUTINE sub( ..., x, y)
REAL, INTENT(IN) :: x(:)
REAL, INTENT(OUT) :: y(:)
is illegal under all versions of Fortran. You are not allowed to modify an
argument that is accessible through more than one "name". The actual phrasing
is such that it is up to the programmer to avoid all such cases, and
compilers are not obligated to report it. The specific example is one that
can be detected through a straightforward static analysis, and tools exist, I
believe FTNCHEK is one, that will detect such cases. However, other examples
exist that can only be detected through prohibitively expensive runtime
analysis, e.g., overlapping array sections of non-unit stride.
There are two justifications for making such code illegal: first even when
the language defines the result of such aliasing the analysis needed to
exploit this definition is complex and error prone in most cases; second,
letting the result of such aliasing be undefined allows significant
optimizations for the vast majority of cases where aliasing would normally
not occur.
For what its worth, users typically find such aliasing to be an extremely
rare source of errors, but also one that is difficult to identify and
understand when it occurs.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|