Incorrect behavior when assigning pointer

Tobias Burnus burnus@net-b.de
Fri Oct 19 20:34:00 GMT 2012


Andrew Benson wrote:
> Here's a simplified version (although, perhaps not simple enough still):
>
> ! These two lines result in the wrong result:
>      allocate(instancesTemporary(2),source=defaultBhC)
>      call Move_Alloc(instancesTemporary,targetNode%cBh)
> ! These two lines give the correct result:
> !!deallocate(targetNode%cBh)
> !!allocate(targetNode%cBh(2))

But the difference is not allocate+move_alloc vs. deallocate+allocate, 
but that you once use
allocate (..., SOURCE=<extended type>)
and once
allocate (<base type> :: ...)


I think I found the bug:

     targetNode%cBh(1)%hostNode => targetNode
     targetNode%cBh(2)%hostNode => targetNode


Here, the memory location for "targetNode%cBh(2)" depends on the size of 
the actual type, which is "Ncbhstd". However, the algorithm assumes that 
one has the declared type ("ncbh"):

(*(struct ncbh[0:] * restrict) 
targetnode->cbh._data.data)[targetnode->cbh._data.offset + 
2].nc.hostnode = (struct tn *) targetnode;

One has to use – as elsewhere – an algorithm which explicitly contains 
_vptr->_size, like it is done in bhget:

(struct __vtype_g_nodes_Ncbh *) __result_bhget._vptr = (struct 
__vtype_g_nodes_Ncbh *) self->_data->cbh._vptr;
__result_bhget._data = (struct ncbh *) self->_data->cbh._data.data + 
(sizetype) ((self->_data->cbh._data.offset + (integer(kind=8)) 
*instance) * (integer(kind=8)) self->_data->c

I have filled the PR http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54992

Tobias



More information about the Fortran mailing list