[Patch] PR fortran/92470 Fixes for CFI_address

Tobias Burnus tobias@codesourcery.com
Tue Nov 12 14:42:00 GMT 2019


Regarding the uncontroversial part: CFI_address. This has been reported 
by Vipul Parekh a few hours ago and the problem is: The lower bounds 
stored in a bind(C) descriptor are either 0 – or, for 
pointer/allocatable arrays, the value used during allocation/pointer 
association (cf. F2018, 18.5.3, para 3, quoted in the PR).

But CFI_address was always assuming 0.

When fixing it, ISO_Fortran_binding_1.f90 started to fail – and looking 
through the code, I run in two problems related to the "lower_bound"s:

(1) CFI_section: Nothing in the standard states, which 'lower_bound's 
shall be used for  'result'. Creating a section in Fortran always gives 
.true. for "any(lbound(array(<section>)) == 1)" – and the CFI array 
descriptors often uses '0' when Fortran has '1'. Another option would be 
to propagate the specified array section on to the CFI descriptor (i.e. 
the specified lower_bounds if not NULL or the "source"'s lower bounds 
(if lower_bound is NULL) – gfortran does the latter.

(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 
– Bob thinks there might be an issue for (2) but both Bob and Bill claim 
that it is well-defined for (1). But I am not convinced. However, as it 
is unclear, I have now reverted my local changes and only kept the non 
lower_bound changes for CFI_establish/CFI_section.

Additionally, the 'dv' value of CFI_establish is some pointer to memory 
which can hold an array descriptor. This memory can contain any garbage 
(e.g. via dv = malloc(…) with glibc's MALLOC_PERTURB_ set). Hence, it 
does not make sense to check 'dv' for a certain value.

Build + regtested on x86_64-gnu-linux.
OK for the trunk? Should it be backported to GCC 9?

Cheers,

Tobias

-------------- next part --------------
A non-text attachment was scrubbed...
Name: bind-c-fix.diff
Type: text/x-patch
Size: 13297 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20191112/658d960d/attachment.bin>


More information about the Fortran mailing list