[Bug fortran/92621] Segmentation fault with assumed rank allocatable intent(out) with bind(c)
jrfsousa at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Feb 21 12:30:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92621
--- Comment #2 from José Rui Faustino de Sousa <jrfsousa at gmail dot com> ---
Looked a bit further into this and found additional problems both under:
gfortran version 10.0.1 20200219 (experimental) (GCC)
and
gfortran version 9.2.1 20200219 (GCC)
With the new test case it will always crash with, infrequently, a segmentation
fault or an attempt to allocate already allocated variable.
From the code generated using -fdump-tree-original:
program alloc_p
alloc_p ()
{
struct array01_integer(kind=4) a;
a.data = 0B;
{
// allocates a
{
void * cfi.9;
// cfi.9 never gets properly initialized and sometimes
// the free tries to deallocate whatever it points to
// generating a segmentation fault
if (cfi.9 != 0B)
{
__builtin_free (cfi.9);
cfi.9 = 0B;
}
<Further initializes a>
// cfi.9 is finally intialized here
cfi.9 = 0B;
// notice that a never got deallocated like it should
_gfortran_gfc_desc_to_cfi_desc (&cfi.9, &a);
a.dtype.attribute = 1; // <- unnecessary duplicate?
// when hello tries to allocate a it will crash with an
// attempt to allocate an already allocated variable
hello (cfi.9);
<...>
}
_gfortran_stop_string (0B, 0, 0);
}
}
It seems that it is generating code that will try to deallocate an
uninitialized pointer, and consequently segfault, and that the memory that
should be freed never is touched so the array will pass on still allocated.
Best regards,
José Rui
More information about the Gcc-bugs
mailing list