[Bug libfortran/108056] [12/13 Regression] backward compatibility issue between 11 and 12

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 12 12:09:31 GMT 2022


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

--- Comment #12 from Tobias Burnus <burnus at gcc dot gnu.org> ---
First, there were several issue in GCC 12 related to using CFI_. Thus, using
GCC 12 is
highly recommended.

This can be seen when implementing the function using the following code (and
removing ', name="sync"' - calling 'void sync(void)' system function):

#include <ISO_Fortran_binding.h>
void bar_ts (CFI_cdesc_t *a, CFI_cdesc_t *b) {
 __builtin_printf ("a = %s, b = %s\n",
   (a->type == CFI_type_float) ? "float" : "something else",
   (b->type == CFI_type_float) ? "float" : "something else");
}


This prints the expected value:
   a = float, b = float

 * * *

In GCC 11, the value that arrives at

  type = GFC_DESCRIPTOR_TYPE (s);

and is then used for

      d->type = (CFI_type_t)type;

is BT_ASSUMED (= 11) instead of the expected BT_REAL (= 3), loosing the data
type.

As d->type is now BT_ASSUMED and this case is not handled, we run into the
code:

  switch (d->type)
...
    default:
      internal_error (NULL, "Invalid type in descriptor");

 * * *

I want to note that both functions,
                 _gfortran_cfi_desc_to_gfc_desc
                 _gfortran_gfc_desc_to_cfi_desc
are only in GCC 12's libgfortran.so to provide backward compatibility with GCC
<= 11.

Thus, we have two options:

(A) We change those to functions back to the GCC 11 version; the new check was
    added in Sandra's commit r12-3321-g93b6b2f614eb692d1d8126ec6cb946984a9d01d7
    back when those functions were still used in GCC 12.

(B) I think we have to possibilities to map this:

BT_ASSUMED -> CFI_type_cptr  or  CFI_type_other; using the latter, that's the
following (untested but it should work):

  -------------------------------------------
--- a/libgfortran/runtime/ISO_Fortran_binding.c
+++ b/libgfortran/runtime/ISO_Fortran_binding.c
@@ -182,4 +182,7 @@ gfc_desc_to_cfi_desc (CFI_cdesc_t **d_ptr, const
gfc_array_void *s)
       d->type = CFI_type_struct;
       break;
+    case BT_ASSUME:
+      d->type = CFI_type_other;
+      break;
     case BT_VOID:
       /* FIXME: PR 100915.  GFC descriptors do not distinguish between
  --------------------------------------------

Thoughts whether (A) or (B) is better?

In any case, we should check whether the testcase of comment 0 plus the C code
above in
this comment should be added as new testcase. But it might very well already be
covered
in our testsuite.


More information about the Gcc-bugs mailing list