Hi José,

(in principle, I'd like to have the libgfortran function moved to the
compiler proper to avoid some issues, but that's admittedly a task
independent of your work.)

On 15.06.21 01:09, José Rui Faustino de Sousa via Fortran wrote:
Update to a proposed patch to:
Bug 93308 - bind(c) subroutine changes lower bound of array argument
in caller
Bug 93963 - Select rank mishandling allocatable and pointer arguments
with bind(c)
Bug 94327 - Bind(c) argument attributes are incorrectly set
Bug 94331 - Bind(C) corrupts array descriptors
Bug 97046 - Bad interaction between lbound/ubound, allocatable arrays
and bind(C) subroutine with dimension(..) parameter
...
Patch tested only on x86_64-pc-linux-gnu.
Fix attribute handling, which reflect a prior intermediate version of
the Fortran standard.

LGTM – except for one minor nit. In trans-expr.c's 
gfc_conv_gfc_desc_to_cfi_desc:

   /* Transfer values back to gfc descriptor.  */
+  if (cfi_attribute != 2
+      && !fsym->attr.value
+      && fsym->attr.intent != INTENT_IN)

Can you add after the '2' the string '  /* CFI_attribute_other.  */'
to make the number less magic.

Thanks,

Tobias



CFI descriptors, in most cases, should not be copied out has they can
corrupt the Fortran descriptor. Bounds will vary and the original
Fortran bounds are definitively lost on conversion.

Thank you very much.

Best regards,
José Rui

Fortran: Fix attributtes and bounds in ISO_Fortran_binding.

gcc/fortran/ChangeLog:

    PR fortran/93308
    PR fortran/93963
    PR fortran/94327
    PR fortran/94331
    PR fortran/97046
    * trans-decl.c (convert_CFI_desc): Only copy out the descriptor
    if necessary.
    * trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): Updated attribute
    handling which reflect a previous intermediate version of the
    standard. Only copy out the descriptor if necessary.

libgfortran/ChangeLog:

    PR fortran/93308
    PR fortran/93963
    PR fortran/94327
    PR fortran/94331
    PR fortran/97046
    * runtime/ISO_Fortran_binding.c (cfi_desc_to_gfc_desc): Add code
    to verify the descriptor. Correct bounds calculation.
    (gfc_desc_to_cfi_desc): Add code to verify the descriptor.

gcc/testsuite/ChangeLog:

    PR fortran/93308
    PR fortran/93963
    PR fortran/94327
    PR fortran/94331
    PR fortran/97046
    * gfortran.dg/ISO_Fortran_binding_1.f90: Add pointer attribute,
    this test is still erroneous but now it compiles.
    * gfortran.dg/bind_c_array_params_2.f90: Update regex to match
    code changes.
    * gfortran.dg/PR93308.f90: New test.
    * gfortran.dg/PR93963.f90: New test.
    * gfortran.dg/PR94327.c: New test.
    * gfortran.dg/PR94327.f90: New test.
    * gfortran.dg/PR94331.c: New test.
    * gfortran.dg/PR94331.f90: New test.
    * gfortran.dg/PR97046.f90: New test.
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf

Reply via email to