------- Comment #5 from burnus at gcc dot gnu dot org 2010-02-25 13:54 ------- type :: thytype integer(4), allocatable :: h(:) end type thytype type :: mytype type(thytype), allocatable :: q(:) end type mytype type (mytype) :: x x = mytype ([thytype([555])]) end
Reduced test case. If I read the dump correctly, one effectively does: tmp = thytype([555]) x = mytype(tmp) however, for "mytype(tmp)" the data is copied instead of simply assigning the pointer "tmp.data" and "tmp.data" is never freed. a) One creates "thytype" with the value 555: (*(struct thytype[1] * restrict) atmp.1.data)[0] = thytype.4; - and recopying again: (*(struct thytype[1] * restrict) atmp.7.data)[S.9] = (*(struct thytype[1] * restrict) atmp.1.data)[S.9]; b) One now assigns that data to "mytype" - but not directly but via malloc+memcopy: D.1592 = (void * restrict) __builtin_malloc (MAX_EXPR <D.1591, 1>); (*(struct thytype[0:] * restrict) mytype.0.q.data)[S.10].h.data = D.1592; __builtin_memcpy ((integer(kind=4)[0:] * restrict) (*(struct thytype[0:] * restrict) mytype.0.q.data)[S.10].h.data, (integer(kind=4)[0:] * restrict) (*(struct thytype[1] * restrict) atmp.7.data)[S.10].h.data, D.1590 * 4); The problem is now that "atmp.7.data.h.data" is never freed. It would be fantastic if instead of freeing atmp.7.data.h.data one could simply assign atmp.7.data.h.data to mytype.0.q.data[S.10].h.data without malloc/memcpy. I am sure it is nontrivial, but I would really like to see the number of temporaries be cut down. The dumps are pretty hard to read and we probably give also the middle end a hard time in figuring out that we do not need ~8 mallocs but one three - especially since the middle end does not really optimize malloc/free (it could, but it doesn't - yet). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38319