[gfortran] Fix NULL reference types.

Toon Moene toon@moene.indiv.nluug.nl
Fri Aug 20 22:01:00 GMT 2004


Dale Johannesen wrote:
>> ie. is the following program legal?
>>
>> subroutine sub1(a, b)
>> if (a > 0) b = log(a)
>> end
>>
>> program prog
>>   integer i, j
>>   call sub1(0, 0)
>>   i = 1
>>   call sub1(i, j)
>> end program
>>
>> Does the fact that b is redefined on some invocations of sub1 imply 
>> that every
>> actual argument associated with b must be definable?
> 
> 
> The language in F77 (15.9.3.2) is:
> "If the actual argument is a constant ... the associated dummy
> argument must not be redefined within the subprogram."
> By itself, that is not totally clear; does that mean redefined
> anywhere in the subprogram, or is redefinition a runtime property?
>  From 15.8.4 it appears that "defined" and "redefined" are indeed
> runtime properties, so this seems to be valid.

The first call to sub1, in itself, is valid.  The subroutine shouldn't 
define b on a call that has a set to zero, because, after all, the body 
of the subroutine says:

if (a > 0) b = log(a).

The problem is the legality of the complete program.  In Fortran, 
there's only one instance of subroutine sub1.  Either it defines (sets) 
b or it doesn't.

Perhaps the correct solution of *this* problem is to compile it as:

subroutine sub1(a, b)
real a, b, c
if (a>0) then
    c = log(a)
    b = c
endif
end

I don't think the current alias analysis - that ascertains that a and b 
don't point to overlapping storage, actually does this.

-- 
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/



More information about the Fortran mailing list