Looks good and I have tested. I will commit after one more double check
for regressions with the test case in the testsuite
I have been following Harris on this one for several days and tested the
patch before submitted here.
Thanks for patch Harris, much appreciated.
Regards,
Jerry
On 1/13/21 8:02 AM, Harris Snyder wrote:
On Wed, Jan 13, 2021 at 1:34 AM Harris Snyder <hsny...@structura.bio> wrote:
Hi everyone,
Sorry, my previous email erroneously referred to unsigned chars / uint8_t,
when I in fact meant signed chars / int8_t. The actual patch works, but the
test case files have ‘uint’ in the file names. I’ll provide a corrected patch
tomorrow to fix the file names.
Harris
Corrected patch below.
OK for master? I don't have write access so I will need someone else
to commit this for me if possible.
Thanks,
Harris Snyder
Fixes a bug in ISO_Fortran_binding.c whereby signed char or int8_t
arrays would cause crashes unless an element size is specified.
Related to PR fortran/93524.
libgfortran/ChangeLog:
* runtime/ISO_Fortran_binding.c (CFI_establish): fixed signed char arrays.
gcc/testsuite/ChangeLog:
* gfortran.dg/iso_fortran_binding_int8_array.f90: New test.
* gfortran.dg/iso_fortran_binding_int8_array_driver.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array.f90
b/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array.f90
new file mode 100644
index 00000000000..31fdf863e0a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array.f90
@@ -0,0 +1,11 @@
+! { dg-do run }
+! { dg-additional-sources iso_fortran_binding_int8_array_driver.c }
+
+module m
+ use iso_c_binding
+contains
+ subroutine fsub( x ) bind(C, name="fsub")
+ integer(c_int8_t), intent(inout) :: x(:)
+ x = x+1
+ end subroutine
+end module
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array_driver.c
b/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array_driver.c
new file mode 100644
index 00000000000..84ed127d525
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array_driver.c
@@ -0,0 +1,25 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include "ISO_Fortran_binding.h"
+
+extern void fsub(CFI_cdesc_t *);
+
+int main(void)
+{
+ int8_t x[] = {1,2,3,4};
+ int N = sizeof(x)/sizeof(x[0]);
+
+ CFI_CDESC_T(1) dat;
+ CFI_index_t ext[1];
+ ext[0] = (CFI_index_t)N;
+ int rc = CFI_establish((CFI_cdesc_t *)&dat, &x, CFI_attribute_other,
+ CFI_type_int8_t, 0, (CFI_rank_t)1, ext);
+ printf("CFI_establish call returned: %d\n", rc);
+
+ fsub((CFI_cdesc_t *)&dat );
+
+ for (int i=0; i<N; i++)
+ printf("%"PRId8"\n", x[i]);
+ return 0;
+}
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array.f90
b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array.f90
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/libgfortran/runtime/ISO_Fortran_binding.c
b/libgfortran/runtime/ISO_Fortran_binding.c
index 86ff25afb23..3746ec1c681 100644
--- a/libgfortran/runtime/ISO_Fortran_binding.c
+++ b/libgfortran/runtime/ISO_Fortran_binding.c
@@ -345,8 +345,7 @@ int CFI_establish (CFI_cdesc_t *dv, void
*base_addr, CFI_attribute_t attribute,
dv->base_addr = base_addr;
if (type == CFI_type_char || type == CFI_type_ucs4_char ||
- type == CFI_type_signed_char || type == CFI_type_struct ||
- type == CFI_type_other)
+ type == CFI_type_struct || type == CFI_type_other)
dv->elem_len = elem_len;
else
{