This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gfortran] Fix NULL reference types.
Paul Brook wrote:
Right, in these two cases we can assume that writes don't trap.
[ Well, the writes might not trap, but the uses of the undefined
variables might.]
No, you can't:
Note that Fortran doesn't specify CALL BY REFERENCE as it's Standardized
calling sequence, and there is a good reason for this.
Consider the following:
SUBROUTINE SUB(A, B)
INTENT IN :: A
INTENT OUT :: B
IF (A > 0) B = LOG(A)
END
A has to be defined on entry (i.e., set).
However, B will only be defined (i.e., set) when A > 0.
An optimizing compiler will copy B (back) to its actual argument *when set*.
This is what John Carr's alias analysis did with Fortran when told about
Fortran specifics.
SUBROUTINE SAXPY(Y,X,A,N)
REAL X(N), Y(N)
DO I = 1, N
Y(I) = Y(I) + A * X(I)
ENDDO
END
It copied A to a floating point register, because alias analysis showed
that A wouldn't be used but for the multiplication, i.e., it wouln't be
copied back.
Now, certainly you could try show that there are specific circumstances
under which this analysis isn't appropriate, but according to Fortran
semantics, it is.
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
A maintainer of GNU Fortran 95: http://gcc.gnu.org/fortran