[Bug fortran/92123] [F2018/array-descriptor] Scalar allocatable/pointer with array descriptor (via bind(C)): ICE with select rank or error scalar variable with POINTER or ALLOCATABLE in procedure with BIND(C) is not yet supported

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 14 14:46:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92123

--- Comment #12 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(all related to gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.f90)

I tried - with Paul's attached patch (attachment 47261)
   DECL_CONTEXT (gfc_desc) = current_function_decl;
instead of TREE_STATIC - but I have the feeling it is unrelated to the real
problem. Or at least, if I have this, I observe the following:

If I remove the 'allocate(dat)', which is not needed as Fortran does
(re)allocate on assignment, it works (-m64 -O1).

However, with the 'allocate(dat)' kept, there are two mallocs – and GCC will
remove the assignment of '42'. Namely:

With -O0, I see in -fdump-tree-optimized:
  gfc_desc_ptr.1_15 = &gfc_desc.0;
  CFI_desc_ptr.2 = dat_12(D);
  _gfortran_cfi_desc_to_gfc_desc (gfc_desc_ptr.1_15, &CFI_desc_ptr.2);
  dat_18 = gfc_desc_ptr.1_15;

  __tmp_INTEGER_4_rank_0_26 = dat_3->data;
  __tmp_INTEGER_4_rank_0_28 = __builtin_malloc (4);
  __tmp_INTEGER_4_rank_0_30 = __builtin_malloc (4);

  # __tmp_INTEGER_4_rank_0_4 = PHI <__tmp_INTEGER_4_rank_0_28(15),
__tmp_INTEGER_4_rank_0_30(16)>
  *__tmp_INTEGER_4_rank_0_4 = 42;    /// <<<<<<<<<<<<
  dat_3->data = __tmp_INTEGER_4_rank_0_4;

  _gfortran_gfc_desc_to_cfi_desc (&CFI_desc_ptr.2, gfc_desc_ptr.1_5);

But with -O1, one has:
  CFI_desc_ptr.2 = dat_14(D);
  _gfortran_cfi_desc_to_gfc_desc (&gfc_desc.0, &CFI_desc_ptr.2);
  # DEBUG dat => &gfc_desc.0

  __tmp_INTEGER_4_rank_0_20 = gfc_desc.0.data;
  __tmp_INTEGER_4_rank_0_22 = __builtin_malloc (4);
  gfc_desc.0.data = __tmp_INTEGER_4_rank_0_22;
  _gfortran_gfc_desc_to_cfi_desc (&CFI_desc_ptr.2, &gfc_desc.0);


More information about the Gcc-bugs mailing list