[Bug fortran/106692] [10/11/12/13 Regression] Cray pointer comparison wrongly optimized away
burnus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Aug 23 14:38:43 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106692
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org
--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Pre-remark: As Cray pointers are outside the spec, it is a bit difficult to
know what to expect. – I do note that it compiles fine with ifort +
optimizations turned on, whatever that means. This and that it did work with
GCC and this PR exists implies that there is real-world code out there which
now fails - but worked before. (Independent whether the code is valid or not.)
* * *
Regarding the code, given that
subroutine shape_cray(zz1)
! REAL :: zz1 ! (implicitly typed)
is a normal variable, I would expect from normal Fortran rules that it is
definable – and, hence, can not be a NULL pointer.
If I wanted to pass a Cray pointer, I would make the dummy argument a Cray
pointer – namely, passing a pointer - and not the pointee:
subroutine shape_cray(ptrzz1) ! << changed to ptrzz1 from zz1 for better
naming
pointer(ptrzz1 , zz1) ! << added line - ptrzz1 is now a cray pointer
pointer(ptrzz, zz)
Accordingly, the callee then has to use:
call shape_cray(ptrzz1) ! pass the pointer
instead of
call shape_cray(zz1)
This also passes by reference (-fdump-tree-original):
void shape_cray (integer(kind=8) & restrict ptrzz1)
but that's the pointer (which must be present) but not the pointee.
When passing the Cray pointer, everything seems to work fine and looks well
defined.
* * *
In my humble opinion, passing a Cray pointer and using a Cray-pointer dummy
argument is the proper Cray-pointer way.
Regarding OPTIONAL - that would work as well, but means the the interface has
to be availble at the callee side, i.e. either an 'interface' block or
shape_cray needs to be contained in a module or in the caller - or it and the
caller need to be contained in the same subprogram (like contained in the
'program').
All of that is fine, but wasn't available in Fortran 77 - the time Cray
pointers were invented.
More information about the Gcc-bugs
mailing list