------- Additional Comments From tkoenig at gcc dot gnu dot org  2005-04-19 
18:51 -------
descriptor.offset (in the front end) aka descriptor->base
in the library is currently useless.

Look at this:

$ cat offset.f90
program main
  real :: a(2,2)
  real, allocatable :: b(:,:)
  real, pointer :: c(:,:)
  call foo(a)
  allocate(b(2,2),c(2,2))
  call foo(b)
  call foo(c)
contains
  subroutine foo(a)
    real, dimension(:,:) :: a
    a(1,1) = 1.0
  end subroutine foo
end program main
$ gfortran -fdump-tree-original offset.f90

>From the .original file:

foo (a)
{
  int4 ubound.0;
  int4 stride.1;
  int4 ubound.2;
  int4 stride.3;
  int4 offset.4;
  real4[0:] * a.0;

  {
    int4 D.484;

    D.484 = a->dim[0].stride;
    stride.1 = D.484 == 0 ? 1 : D.484;
    a.0 = (real4[0:] *) a->data;
    ubound.0 = a->dim[0].ubound - a->dim[0].lbound + 1;
    stride.3 = a->dim[1].stride;
    ubound.2 = a->dim[1].ubound - a->dim[1].lbound + 1;
    offset.4 = -stride.1 - NON_LVALUE_EXPR <stride.3>;
  }
  (*a.0)[NON_LVALUE_EXPR <stride.1> + NON_LVALUE_EXPR <stride.3> + offset.4] =
1.0e+0;
}

You can see that offset.4 is calculated without a reference to a->offset.
This is a good thing, because the offset is only calculated correctly
for static arrays:

MAIN__ ()
{
  struct array2_real4 c;
  real4 a[4];
  struct array2_real4 b;
  static void foo (struct array2_real4 &);

  c.data = 0B;
  b.data = 0B;
  {
    struct array2_real4 parm.5;

    parm.5.dtype = 282;
    parm.5.dim[0].lbound = 1;
    parm.5.dim[0].ubound = 2;
    parm.5.dim[0].stride = 1;
    parm.5.dim[1].lbound = 1;
    parm.5.dim[1].ubound = 2;
    parm.5.dim[1].stride = 2;
    parm.5.data = (real4[0:] *) (real4[0:] *) &a[0];
    parm.5.offset = 0;
             ^^^^^^^^^^
             This is wrong.
    foo (&parm.5);
  }

For allocated and pointer arrays, this is done correctly:
 {
    real4[0:] * * D.504;

    b.dtype = 282;
    b.dim[0].lbound = 1;
    b.dim[0].ubound = 2;
    b.dim[0].stride = 1;
    b.dim[1].lbound = 1;
    b.dim[1].ubound = 2;
    b.dim[1].stride = 2;
    D.504 = &b.data;
    _gfortran_allocate (D.504, 16, 0);
    b.offset = -3;
             ^^^^^^^
             correct
  }
  {
    real4[0:] * * D.505;

    c.dtype = 282;
    c.dim[0].lbound = 1;
    c.dim[0].ubound = 2;
    c.dim[0].stride = 1;
    c.dim[1].lbound = 1;
    c.dim[1].ubound = 2;
    c.dim[1].stride = 2;
    D.505 = &c.data;
    _gfortran_allocate (D.505, 16, 0);
    c.offset = -3;
             ^^^^^^
             correct
  }
  foo (&b);
  foo (&c);

The assert is therefore false and should be removed.

The question remains: What to do with the offset field?
Fix it in the front end for static arrays, or remove it
altogether?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Thomas dot Koenig at online
                   |                            |dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18857

Reply via email to