This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFA: Revamp fortran array types
On Tue, Aug 18, 2009 at 06:01:46PM +0200, Tobias Burnus wrote:
> On 08/18/2009 05:14 PM, Steve Kargl wrote:
> > On Tue, Aug 18, 2009 at 04:40:17PM +0200, Michael Matz wrote:
> >
> >> ----------------------------------
> >> integer, target :: foo
> >> integer, pointer :: p,p2
> >> integer :: i
> >> p=>foo
> >> p2=>foo
> >> i = clobber(p,p2)
> >> if (i /= 2) call abort
> >> contains
> >> function clobber(p,p2)
> >> integer clobber
> >> integer, pointer :: p,p2
> >> p = 1
> >> p2 = 2
> >> clobber = p
> >> end function
> >> end
> >> ----------------------------------
> >>
> >> An unpatched compiler with "-O2 -fno-inline" will make this testcase
> >> abort, exactly due to the hack called flag_argument_noalias.
> >>
> > The above code is technically invalid Fortran, so a compiler
> > can do whatever it wants. The abort is a possible "correct"
> > result. The standard prohits a programmer from aliasing
> > the input arguments. The standard also does not require a
> > compiler to detect aliasing.
> >
>
> I think this is oversimplified:
>
> "12.5.2.13 Restrictions on entities associated with dummy arguments"
> "Action that affects the value of the entity or any subobject of it
> shall be taken only through the dummy argument unless ... the actual
> argument is a target"
>
> (For pointer it presumably means the target to which the pointer points
> to, i.e. those are covered as well.)
>
> Thus the example looks fine to me - unless I missed some fine-print
> somewhere.
>
> (Quote taken from the last Fortran 2008 draft, cf.
> http://gcc.gnu.org/wiki/GFortranStandards; other relevant quotes for
> aliasing are:
> "5.3.17 TARGET attribute": "The TARGET attribute specifies that a data
> object may have a pointer associated with it (7.2.2). An object without
> the TARGET attribute shall not have a pointer associated with it."
> "If the dummy argument has the TARGET attribute and the effective
> argument does not have the TARGET attribute or is an array section with
> a vector subscript, any pointers associated with the dummy argument
> become undefined when execution of the procedure completes." (12.5.2.4
> Ordinary dummy variables).)
REMOVE:kargl[108] cat k.f90 l.f90
! k.f90
program a
integer, target :: b
integer, pointer :: p1, p2
integer j
interface
integer function clobber(x,y)
integer, pointer, intent(in) :: x
integer, pointer, intent(out) :: y
end function clobber
end interface
b = 1
p1 => b
p2 => b
j = clobber(p1, p2)
print *, j, p1
end program a
!
! l.f90
!
integer function clobber(x,y)
integer, pointer, intent(in) :: x
integer, pointer, intent(out) :: y
print *, x
y = 2
clobber = x
end function clobber
REMOVE:kargl[109] gfc4x -o z k.f90 l.f90
REMOVE:kargl[110] ./z
1
2 2
The assignment to y has changed the intent(in) x.
--
Steve