------- Comment #9 from janus at gcc dot gnu dot org 2009-10-20 19:56 ------- Apart from the double free issue, there might be a more fundamental problem with PACK and arrays of derived types. For me, Tobias' test case from comment #8 segfaults already in the call to _gfortran_pack, and so does the following:
type :: container_t integer:: entry = -1 end type container_t type(container_t), dimension(1) :: a1, a2 a2(1)%entry = 1 print *,a1,a2 a1 = pack (a2, mask = [.true.]) print *,a1,a2 end This does not have any allocatables (so no auto-dealloc happens), but the output is: -1 1 Segmentation fault which means the second print statement is not reached, i.e. the segfault seems to happen in _gfortran_pack. The part of the dump which corresponds to the call to PACK looks like this: { struct array1_logical(kind=4) parm.4; static logical(kind=4) A.3[1] = {1}; struct array1_container_t parm.2; struct array1_container_t parm.1; parm.1.dtype = 297; parm.1.dim[0].lbound = 1; parm.1.dim[0].ubound = 1; parm.1.dim[0].stride = 1; parm.1.data = (void *) &a1[0]; parm.1.offset = -1; parm.2.dtype = 297; parm.2.dim[0].lbound = 1; parm.2.dim[0].ubound = 1; parm.2.dim[0].stride = 1; parm.2.data = (void *) &a2[0]; parm.2.offset = -1; parm.4.dtype = 273; parm.4.dim[0].lbound = 1; parm.4.dim[0].ubound = 1; parm.4.dim[0].stride = 1; parm.4.data = (void *) &A.3[0]; parm.4.offset = 0; _gfortran_pack (&parm.1, &parm.2, &parm.4, 0B); } The above test case works when making a1 and a2 simple integers. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41478