This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: Revamp fortran array types


Hi,

On Tue, 18 Aug 2009, Steve Kargl 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
> > ----------------------------------
> > 
> 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.

I knew this, but assumed that the above testcase doesn't contain argument 
aliasing.  It's two different arguments and variables that happen to be 
pointers, and the target of them aliases.  I somehow thought the standard 
tried to forbid this or similar situations:

  function f (a,b)
   real :: a,b
   a = 42
   f = b
  end
  real :: x
  call f(x,x)

i.e. where the arguments itself are the same storage.  Seems I was wrong.

In any case, would the following be valid fortran (in the sense that 
abort must not be called)?

------------
  integer, target :: foo
  integer, pointer :: p
  integer :: i
  p=>foo
  i = clobber(p)
  if (i /= 2) call abort
contains
  function clobber(p)
    integer clobber
    integer, pointer :: p
    foo = 1
    p = 2
    clobber = foo
  end function
end
------------

Because if it is valid, it would result in the same miscompile, if it 
weren't for some (un)lucky details in our aliasing machinery (i.e. right 
now the above doesn't miscompile, but if we ever would clean up the alias 
machinery it would).

> With that said, I regression tested your patch on amd64-*-freebsd.
> There were no regressions.  Tobias has already approved your
> patch, and I see no reason to not commit it (based on Tobias's
> Polyhedron benchmark results).

Yep, thanks.


Ciao,
Michael.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]