[Bug fortran/92621] Segmentation fault with assumed rank allocatable intent(out) with bind(c)

2020-02-21 Thread jrfsousa at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92621

--- Comment #3 from José Rui Faustino de Sousa  ---
Created attachment 47882
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47882=edit
New test case

[Bug fortran/92621] Segmentation fault with assumed rank allocatable intent(out) with bind(c)

2020-02-21 Thread jrfsousa at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92621

--- Comment #2 from José Rui Faustino de Sousa  ---
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;
}



// cfi.9 is finally intialized here

  cfi.9 = 0B;

// notice that a never got deallocated like it should

  _gfortran_gfc_desc_to_cfi_desc (, );
  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

[Bug fortran/92621] Segmentation fault with assumed rank allocatable intent(out) with bind(c)

2019-11-21 Thread jrfsousa at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92621

--- Comment #1 from José Rui Faustino de Sousa  ---
Created attachment 47327
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47327=edit
C code