https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81748

--- Comment #2 from janus at gcc dot gnu.org ---
Slightly reduced test case:

program z
  implicit none
  type t1
    integer :: age
  end type
  type, extends( t1 ) :: t2
    real :: height_cm
  end type
  type( t2 ) :: p( 4 )
  p % age = (/ 1,2,3,4 /)
  call s( p )
  call s( p % t1 )
contains
  subroutine s( man )
    class( t1 ) :: man(:)
    write (*,*) man % age
  end subroutine
end

This prints something like:

           1           2           3           4
           1           0           2  1659587003

where the second line is obviously wrong.

-fdump-tree-original shows that the class containers that are build for the two
calls to 's' have exactly the same data, but different vptr, which is certainly
wrong:

  {
    struct __class_z_T1_1_0t class.8;
    struct array01_t2 parm.9;

    class.8._vptr = (struct __vtype_z_T1 * {ref-all}) &__vtab_z_T2;
    parm.9.dtype = {.elem_len=8, .rank=1, .type=5};
    parm.9.dim[0].lbound = 1;
    parm.9.dim[0].ubound = 4;
    parm.9.dim[0].stride = 1;
    parm.9.data = (void *) &p[0];
    parm.9.offset = -1;
    class.8._data = parm.9;
    s (&class.8);
  }
  {
    struct __class_z_T1_1_0t class.10;
    struct array01_t2 parm.11;

    class.10._vptr = (struct __vtype_z_T1 * {ref-all}) &__vtab_z_T1;
    parm.11.dtype = {.elem_len=8, .rank=1, .type=5};
    parm.11.dim[0].lbound = 1;
    parm.11.dim[0].ubound = 4;
    parm.11.dim[0].stride = 1;
    parm.11.data = (void *) &p[0];
    parm.11.offset = -1;
    class.10._data = parm.11;
    s (&class.10);
  }

Reply via email to