Re: [Patch, Fortran] PR91863 - fix call to bind(C) with array descriptor

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: [Patch, Fortran] PR91863 - fix call to bind(C) with array descriptor

Paul Richard Thomas
Hi Tobias,

Thanks for taking care of this. OK for trunk and 9-branch.



On Wed, 23 Oct 2019 at 14:07, Tobias Burnus <[hidden email]> wrote:

> With the trunk, there are three issues:
> (a) With bind(C), the callee side handles deallocation with intent(out).
> This should produce the code:
>      if (cfi.0 != 0B)
>        {
>          __builtin_free (cfi.0);
>          cfi.0 = 0B;
>        }
> This fails as cfi.0 (of type 'void*') is dereferenced and
> *cfi.0 = 0B' (i.e. assignment of type 'void') causes the ICE.
> (b) With that fixed, one gets:
>      sub (cfi.4);
>      _gfortran_cfi_desc_to_gfc_desc (&a, &cfi.4);
>      if (cfi.4 != 0B)
>        __builtin_free (cfi.4);
>      ... code using "a" ...
> That also won't shine as '' == 'cfi.4'; hence, one
> accesses already freed memory.
> I don't see whether freeing the cfi memory makes sense at all;
> as I didn't come up with a reason, I removed it for good.
> Those issues, I have solved. The third issue is now PR fortran/92189:
> (c) When allocating memory in a Fortran-written Bind(C) function, the
> shape/bounds changes are not propagated back to Fortran.
> Namely, "sub" lacks some _gfortran_gfc_desc_to_cfi_desc call at the end!
> The issue pops up, if you change 'dg-do compile' into 'dg-do run'. For
> using a C-written function, that's a non-issue. Hence, it makes sense
> to fix (a)+(b) of the bug separately.
> OK for the trunk and GCC 9? (At least the ICE is a regression.)
> Tobias

"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein