This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/27470] [4.1/4.2 regression] wong memory allocator for derived types



------- Comment #2 from tkoenig at gcc dot gnu dot org  2006-05-07 19:36 -------
(In reply to comment #1)
> I wonder how related this is to PR 27411.

As far as I can see, there's no relationship.  To my eye, this looks
like a stand-alone bug :-)

Summary of what goes wrong:

gfc_array_allocate needs to differentiate between pointer and
allocatable arrays because it needs to call _gfortran_allocate_array for
allocatable arrays and _gfortran_allocate for pointers.  The difference
is that, for an allocatable array, it is an error if the allocatable
array is already allocated.  For pointers, it's ok (it potentially
leaks memory, though).

The test wether this is an allocatable array is done via

expr->symtree->n.sym->attr.allocatable, which is fine for non-derived
types.  The test case exposes a problem, that "mol" is allocatable,
mol%array is a pointer, and what we get via expr->symtree->... is
the array and not the pointer.  Apparently, we need to look somewhere
else for that information, but I haven't found out where yet.

Here is a test case which actually provokes a runtime error:


  TYPE foo
    INTEGER, DIMENSION(:), POINTER :: array
  END TYPE foo

  type(foo),allocatable,dimension(:) :: mol

  ALLOCATE (mol(1))
  mol = transfer(-1, mol)  ! Initialize the array with garbage
  ALLOCATE (mol(1)%array(5)) ! Fails with "Attempting to allocate already
allocated array"

  END


-- 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]