[Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Aug 11 14:11:50 GMT 2021


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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #19 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 51289
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51289&action=edit
Patch - Free memory in the callee

The attached patch frees the memory in the callee, however:

* integer, allocatable – those are passed as 'integer **dummy'
  I believe those should be passed as CFI descriptor
  -> runs into the assert.

* In the Fortran caller, the freeing is not needed if the the implementation is
in Fortran as the callee frees this. In principle, something like the following
should work (trans-expr; there is one case for scalar and one for arrays):
@@ -6541 +6548,3 @@ gfc_conv_procedure_call
-                 && fsym->attr.intent == INTENT_OUT)
+                 && fsym->attr.intent == INTENT_OUT
+                 && (!sym->attr.is_bind_c
+                     || sym->attr.if_source != IFSRC_DECL))

However, that does not work – and shows that the gfortran → CFI conversion is
completely broken:
    void * cfi.0;
    if (cfi.0 != 0B)
      {
        __builtin_free (cfi.0);
That's uninitialized memory :-(

* Also broken is that the data type for BIND(C) uses the Fortran array
descriptor and not the CFI one – it is currently only used as pointer and later
cast to void* but still that's pretty bad :-(

 * * *

I have still to look at José's patches.

 * * *

In any case, I think that the TYPE handling needs to be fixed first, followed
by moving _gfortran_gfc_desc_to_cfi_desc (and cfi→gfc) from libgfortran to the
front end to generate proper context-aware in-line code.


More information about the Gcc-bugs mailing list