Hi all,
during debugging I found an odd value in the offset member of the fortran array
descriptor. Given the following fortran program fragment (full source attached):
subroutine AddArray(P, dp)
class(*), target, intent(in) :: P(:)
double precision, dimension(:) :: dp
! ...
end subroutine
double precision P(2,2)
P(1:2,1)=[1.d0,2.d0]
P(1:2,2) = [3.d0,4.d0]
call AddArray(P(1:2,2), P(1:2,2))
The pseudo code for the call of Addarray (full file attached, too) comes like
this:
struct array1_real(kind=8) parm.20;
struct array1_real(kind=8) parm.19;
struct __class__STAR_1_0t class.18;
class.18._vptr = (struct __vtype__STAR * {ref-all}) &__vtab_REAL_8_;
parm.19.dtype = 537;
parm.19.dim[0].lbound = 1;
parm.19.dim[0].ubound = 2;
parm.19.dim[0].stride = 1;
parm.19.data = (void *) &p[2];
parm.19.offset = 0; // *1
class.18._data = parm.19;
parm.20.dtype = 537;
parm.20.dim[0].lbound = 1;
parm.20.dim[0].ubound = 2;
parm.20.dim[0].stride = 1;
parm.20.data = (void *) &p[2];
parm.20.offset = -3; // *2
addarray (&class.18, &parm.20);
For both parm.__.offset fields I don't get why that value is chosen. IMHO both
should be -1. My reason to believe that the value in case *1 should be minus
one is that lbound for dimension zero is set to 1 and the data-member is
set to the third value in the linear mapping of the array P. Or with other words
parm.19.data is pointing to 3.d0 in P, which is absolutely correct from the
data perspective. But, because the array descriptor is using an .lbound of 1, I
would expect to have that counteracted by the .offset given that element
addressing in the subroutine is using the offset to (re-)base the data access.
The next really interesting issue is, why at *2 an offset of -3 is used. Can
anyone explain, why one would need to model here that two elements in the
original array are skipped while the data pointer is set correctly? I would
understand to have parm.20.data = &p[0] and parm.20.offset = 1 or parm.20.data =
&p[2] and parm.20.offset = -1 both enabling to access the first element in the
array in the subroutine using P(1) translated into parm.20.data[parm.20.offset
+ 1].
Any ideas?
Regards,
Andre
--
Andre Vehreschild * Email: vehre ad gmx dot de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_pr64692.f90
Type: text/x-fortran
Size: 729 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150221/65edca29/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_pr64692.f90.003t.original
Type: application/octet-stream
Size: 9567 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150221/65edca29/attachment.obj>