aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry DeLisle <jvdelisle@gcc.gnu.org>2021-01-15 13:48:42 -0800
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2021-01-15 13:48:42 -0800
commitb90e4a97419ce91fd7c1628b5912e8f54bee3441 (patch)
tree1807faef01186a476a9229245048bc0af4454eeb
parent9beb6d88effdab4209beb8bc5e4b8773317f1d33 (diff)
downloadgcc-b90e4a97419ce91fd7c1628b5912e8f54bee3441.zip
gcc-b90e4a97419ce91fd7c1628b5912e8f54bee3441.tar.gz
gcc-b90e4a97419ce91fd7c1628b5912e8f54bee3441.tar.bz2
fortran: Fixes a bug in ISO_Fortran_binding.c.
libgfortran/ChangeLog: * runtime/ISO_Fortran_binding.c (CFI_establish): Fixed signed char arrays. Signed char or uint8_t arrays would cause crashes unless an element size is specified. gcc/testsuite/ChangeLog: * gfortran.dg/iso_fortran_binding_uint8_array.f90: New test. * gfortran.dg/iso_fortran_binding_uint8_array_driver.c: New test.
-rw-r--r--gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array.f9011
-rw-r--r--gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c25
-rw-r--r--libgfortran/runtime/ISO_Fortran_binding.c3
3 files changed, 37 insertions, 2 deletions
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array.f90 b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array.f90
new file mode 100644
index 0000000..b28bfa7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array.f90
@@ -0,0 +1,11 @@
+! { dg-do run }
+! { dg-additional-sources iso_fortran_binding_uint8_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_uint8_array_driver.c b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
new file mode 100644
index 0000000..bfd567b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_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/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c
index 86ff25a..3746ec1 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
{