Hi all,

On 11/12/19 3:42 PM, Tobias Burnus wrote:
(2) CFI_establish: For allocatables, it is clear – base_addr == NULL. For pointers, it is clear as well – it has to be '0' according to the standard. But for CFI_attribute_other … I have now asked at https://mailman.j3-fortran.org/pipermail/j3/2019-November/thread.html#11740

While I still have problems to decipher the standard, regarding CFI_establish, Steve L wrote:

"In the C descriptor world, arrays start at zero as they do in C. The only way they can become non-zero is through argument association, allocation or pointer association as specified in 18.5.3p3. For non-pointer, not-allocatable objects (this means "other"), the lower bounds are supposed to be always zero."

Hence, I now also set it for CFI_attribute_other to 0 – and check it in a test case (most users there have NULL as base_addr, hence, only a single assert is in that file).

Build on x86-64_gnu-linux.
OK for the trunk and GCC-9?

Tobias

2019-11-12  Tobias Burnus  <tob...@codesourcery.com>

	libgfortran/
	PR fortran/92470
	* runtime/ISO_Fortran_binding.c (CFI_establish): Set lower_bound to 0
	also for CFI_attribute_other.

	gcc/testsuite/
	PR fortran/92470
	* gfortran.dg/ISO_Fortran_binding_1.c (establish_c): Add assert for
	lower_bound == 0.

diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
index 091e754d8f9..a5714593c52 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
@@ -109,6 +109,7 @@ int establish_c(CFI_cdesc_t * desc)
 		      CFI_attribute_pointer,
 		      CFI_type_struct,
 		      sizeof(t), 1, extent);
+  assert (desc->dim[0].lower_bound == 0);
   for (idx[0] = 0; idx[0] < extent[0]; idx[0]++)
     {
       res_addr = (t*)CFI_address (desc, idx);
diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c
index 7ae2a9351da..91d9ae46d3d 100644
--- a/libgfortran/runtime/ISO_Fortran_binding.c
+++ b/libgfortran/runtime/ISO_Fortran_binding.c
@@ -387,13 +387,7 @@ int CFI_establish (CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute,
 
       for (int i = 0; i < rank; i++)
 	{
-	  /* If the C Descriptor is for a pointer then the lower bounds of every
-	   * dimension are set to zero. */
-	  if (attribute == CFI_attribute_pointer)
-	    dv->dim[i].lower_bound = 0;
-	  else
-	    dv->dim[i].lower_bound = 1;
-
+	  dv->dim[i].lower_bound = 0;
 	  dv->dim[i].extent = extents[i];
 	  if (i == 0)
 	    dv->dim[i].sm = dv->elem_len;

Reply via email to