User account creation filtered due to spam.

Bug 52044 - [OOP] Invalid memory access with ALLOCATE, default initializer and polymorphic array components
Summary: [OOP] Invalid memory access with ALLOCATE, default initializer and polymorphi...
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
Keywords: wrong-code
Depends on:
Reported: 2012-01-29 18:15 UTC by Tobias Burnus
Modified: 2016-11-16 14:32 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-01-29 18:15:16 UTC
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: = (void * restrict) __builtin_malloc (96);
  D.1899 = (struct t[0:] * restrict);
  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 " = 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
Comment 1 Tobias Burnus 2012-01-29 18:49:07 UTC
The test case mentioned in comment 0 is test4() of the patch submitted at
Comment 2 Paul Thomas 2012-02-06 21:24:12 UTC
This is now fixed, since __builtin_memset (, 0, 96); appears after allocation.

Thanks for this and all the other extracts from Damian and co.'s book!