[Bug fortran/52044] New: [OOP] Invalid memory access with ALLOCATE, default initializer and polymorphic array components

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Jan 29 18:36:00 GMT 2012


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

             Bug #: 52044
           Summary: [OOP] Invalid memory access with ALLOCATE, default
                    initializer and polymorphic array components
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


This is a follow up to PR 51972 - or rather it's included test case.

The following program fails at run time with a segfault, cf:

  Conditional jump or move depends on uninitialised value(s)
    at 0x400932: __copy_MAIN___T (nb54af.f90:6)
    by 0x400B96: MAIN__ (nb54af.f90:11)

>From the dump:
  two.a._data.data = (void * restrict) __builtin_malloc (96);
  D.1899 = (struct t[0:] * restrict) two.a._data.data;
  D.1903 = *two.a._vptr->_def_init
  two.a._vptr->_copy (&D.1903,
                      D.1899 + ((S.2 + D.1900) * two.a._vptr->_size));

Thus, there is a MEMSET '\0', CALLOC, or "two.a._data.data = 0" missing as
_copy checks the value of the "dst" argument.

Probably, there is an issue with checking for "component->attr.allocatable"
while on only has "CLASS_DATA (component)->attr.allocatable". I assume that
attr.alloc_comp is correctly set, but the nullification is missed when
iterating over the components. Or there is no nullification with _def_init?


  type t
    integer, allocatable :: x(:)
  end type t

  type t2
    class(t), allocatable :: a(:)
  end type t2

  type(t2) :: two

  allocate (two%a(2)) ! ICE: SEGFAULT
end



More information about the Gcc-bugs mailing list