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

             Bug #: 50959
           Summary: [OOP] Redundant setting of the vptr
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bur...@gcc.gnu.org
                CC: ja...@gcc.gnu.org


It is pointless to store the vptr if one does not use it.

Example: The invalid ("x" is not allocated) code
  use m
  class(t), allocatable :: x
  j = x%i
produces the dump:
      x._data = 0B;
      (struct __vtype_m_T *) x._vptr = &__vtab_m_T;
      j = x._data->i;

There is no point for the "x._vptr = ". The vptr for pointers/allocatable
should only be set for ALLOCATE (explicit or polymorphic intrinsic) or pointer
assignment - but not as part of the initialization.

For a more real-world example, see below. There one has:

      (struct __vtype_m_T *) x._vptr = &__vtab_m_T;
      /* malloc block */
      (struct __vtype_m_T *) x._vptr = &__vtab_m_T;
where the last line is part of the ALLOCATE.


module m
  type t
  contains
    procedure, nopass :: bar => base
  end type t

  type, extends(t) :: t2
  contains
    procedure, nopass :: bar => ext
  end type t2
contains
  subroutine base()
    write(*,*) 'BASE t1'
  end subroutine
  subroutine ext()
    write(*,*) 'EXT t2'
  end subroutine
end module

program test
  use m
  class(t), allocatable :: x
  allocate (t :: x)
  call x%bar ()
end program test

Reply via email to