[comp.lang.misc] Detection of aliasses

dik@cwi.nl (Dik T. Winter) (03/02/90)

Note: this is for Fortran 77 only.
(For comp.lang.fortran readers, ignore the references about previous
postings.)

I am taking this up in private mail with Jim Giles.  However there is one
interesting point remaining:  I wrote about a routine that tried to detect
aliassing of input parameters.  Jim wrote that failure to detect aliassing
in that special case would only influence the efficiency of the code
involved.  However, my opinion is that any attempt to detect aliassing in
a Fortran routine invalidates the code.  I would like to see counter
examples (because on occasion I would like to do it).  So if you have a
portable way to detect aliassing, mail it to me.  Either I will send
back a refutation or I will post the solution.
-- 
dik t. winter, cwi, amsterdam, nederland
dik@cwi.nl

jlg@lambda.UUCP (Jim Giles) (03/03/90)

From article <8860@boring.cwi.nl>, by dik@cwi.nl (Dik T. Winter):
> [...]      However, my opinion is that any attempt to detect aliassing in
> a Fortran routine invalidates the code.  [...]                        

Oh yes, absolutely.  If, by "invalidates", you mean that the code becomes
non-standard: you're absolutely correct.  The only way to detect aliasing
(unless the compiler does it for you automatically) is to rely on extra-
linguistic aids - loc() functions for example.  Such aids can not be written
in Fortran (so they are clearly not "standard Fortran").

Although these extra-linguistic tools aren't Fortran - _calling_them_ is
not against the standard.  So, using them to detect aliasing is a quite
legitimate use of non-Fortran subroutine libraries.  Of course, any such
use will not be portable to an environment which doesn't support the
extra-linguistic tools that you rely on.  However, in the case you gave
(namely: two input parameters which are either disjoint or identical),
the detection of aliasing requires a simple compare of the loc() of
each parameter.  Not many environments fail to provide a loc() function
(or, at least, the possibility of writing one yourself in assembly).

One last point: if your procedure interface is implemented as call by
value/result, aliasing is not possible.  So the detection mechanism
would have to be modified so that is never claimed a match (or, take
the detection code out when you port to a value/result environment).

J. Giles