[Bug fortran/92470] New: CFI_address wrongly assumes that lower bounds are at zero – invalid for pointers + allocatables
burnus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Nov 12 08:44:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92470
Bug ID: 92470
Summary: CFI_address wrongly assumes that lower bounds are at
zero – invalid for pointers + allocatables
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
Target Milestone: ---
Mentioned at https://gcc.gnu.org/ml/fortran/2019-11/msg00060.html
refers to
https://github.com/j3-fortran/fortran_proposals/issues/57#issuecomment-552680503
(the two Fortran codes in this comment are identical).
The problem is the handling of the lower bound and CFI_address.
Passing a Fortran array to bind(C), one has for the bounds (F2018, 18.5.3, para
3):
"For a C descriptor of an array pointer or allocatable array, the value of the
lower_bound member of each element of the dim member of the descriptor is
determined by argument association, allocation, or pointer association.
For a C descriptor of a nonallocatable nonpointer object, the value of the
lower_bound member of each element of the dim member of the descriptor is
zero."
Hence, for allocate(A(-2:5)) - A's lower bound has also in C the value -2.
Thus, when calling
CFI_address(dv, lb);
with lb = -2, the result should be the original unmodified "data" pointer.
The problem is that CFI_address assumes that the lower bound is 0;
libgfortran/runtime/ISO_Fortran_binding.c has:
base_addr = base_addr + (CFI_index_t)(subscripts[i] * dv->dim[i].sm);
Expected: Either add a case separation (e.g. based on the type) or
unconditionally honour the lower bound value.
More information about the Gcc-bugs
mailing list