Janne Blomqvist wrote:
Fortran does not allow aliasing of dummy arguments,
That's not quite true: It permits aliasing variables (also without
TARGET or POINTER attribute) – but if you modify one, you may no longer
access the other, unless they do have the POINTER or TARGET attribute.
(See below for the formal description.)
so a compiler is allowed to optimize assuming aliasing does not occur.
The exception is dummy arguments with the POINTER attribute, those can
alias with other variables having the POINTER or TARGET attributes. So
an ALLOCATABLE variable can not alias with any other variable, unless
it has the TARGET attribute.
Well, two variables with TARGET attribute are also permitted to alias.
Tobias
PR: Now the same as above, but using a quote from Fortran 2008:
"12.5.2.13 Restrictions on entities associated with dummy arguments
While an entity is associated with a dummy argument, the following
restrictions hold.
(1) Action that affects the allocation status of the entity or a
subobject thereof shall be taken through the dummy argument.
(2) If the allocation status of the entity or a subobject thereof is
affected through the dummy argument,
then at any time during the invocation and execution of the procedure,
either before or after the allocation or deallocation, it shall be
referenced only through the dummy argument.
(3) Action that affects the value of the entity or any subobject of it
shall be taken only through the
dummy argument unless
(a) the dummy argument has the POINTER attribute or
(b) the dummy argument has the TARGET attribute, the dummy argument
does not have INTENT(IN), the dummy argument is a scalar object or an
assumed-shape array without the CONTIGUOUS attribute, and the actual
argument is a target other than an array section with a vector subscript.
(4) If the value of the entity or any subobject of it is affected
through the dummy argument, then at any time during the invocation and
execution of the procedure, either before or after the definition, it
may be referenced only through that dummy argument unless
(a) the dummy argument has the POINTER attribute or
(b) the dummy argument has the TARGET attribute, the dummy argument does
not have INTENT(IN), the dummy argument is a scalar object or an
assumed-shape array without the CONTIGUOUS attribute, and the actual
argument is a target other than an array section with a vector subscript."