Aleksandar Donev writes:
> Richard Maine wrote:
>
> > Yes, this appears safe. That is very much the kind of reason why
> > things have the target attribute in general - nothing new to C interop
> > in this. You'd have the same issue if you had a Fortran pointer,
> > pointed it at x, and then called some Fortran subroutine with that
> > pointer a an argument.
>
> Not quite. Fortran compilers often do aliasing-type analysis on pointers, so
> they may be perfectly able to prove that p cannot point to any part of x and
> then proceed to optimize. With C_LOC there is no real pointer assignment, so
> this was my concern.
C_LOC effectively *IS* a pointer assignment, "real" or not. That's
why it's argument has to have the target attribute. If the compiler
does that kind of analysis, then it will just have to get it right
with C_LOC also. Getting it "right" could conceivably involve
something as crude as noticing that there is a CPTR around somewhere,
so all pointers are assumed to be possibly aliased. This is exactly
one of the kinds of questions that concerned some people in objecting
to C_LOC and C_F_POINTER - that it might hurt optimization. I think
we've convinced people that isn't substantially different from current
issues with purely Fortran pointers. (But this is one of the things
you have to be careful about in trying to extend C_LOC).
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|