https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110415
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Andrew Jenner's submitted patch (gcc-patches@ only):
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636671.html
and (fortran@ only):
https://gcc.gnu.org/pipermail/fortran/2023-November/059928.html
(Replies should got to both lists ...)
* * *
Technical it is a regression caused by
https://gcc.gnu.org/r13-6747-gd7caf313525a46f200d7f5db1ba893f853774aee
but before that commit there was no finalization.
Comparing the versions:
GCC 7+8: ICE in build_function_decl
GCC 10+11+12: memory leak in 'func'
GCC 13+mainline: segfault at runtime (at 'a = func()' in the main program).
* * *
I had analyzed the issue the elsewhere, let's copy it here for completeness and
possibly to aid the patch review. (Note: The following was written before the
patch was written and analyzed the current status.)
---<cut-----
The 'func' has the prototype 'struct __class_MAIN___P_a func ()', i.e. returns
the class-wrapper directly - and that part looks okay.
However, the assignment somehow mixes everything up:
D.4349 = a->_vptr; // save old value of vptr
D.4328 = func (); // new value
desc.0.data = (void * restrict) D.4328._data;
// As scalar, there is not really a problem, but an
// desc.0.dtype.elem_len = D.4328->_vptr->size;
// is missing here.
desc.0.span = (integer(kind=8)) desc.0.dtype.elem_len;
if (__builtin_expect ((integer(kind=8)) (a->_data == 0B), 0, 42))
a->_data = (struct p *) __builtin_malloc (MAX_EXPR <(unsigned long)
a->_vptr->_size, 1>);
// WRONG: That should use D.4328->_vptr->size!
else
{
if (a->_vptr != D.4349)
{
__builtin_realloc ((void *) a->_data, a->_vptr->_size);
Likewise: a->_vptr should be D.4328->_vptr.
Alternatively, a->_vptr had to be updated before the 'if' block.