[Patch, fortran] PR98342 - Allocatable component in call to assumed-rank routine causes invalid pointer
Paul Richard Thomas
paul.richard.thomas@gmail.com
Fri Jan 29 14:20:28 GMT 2021
Fixing the different variants of this PR was somewhat like drawing teeth.
Fixing the scalar problem with derived type and class formal arguments was
straightforward. However, the need to strip NOPS for scalar unlimited
polymorphic arguments was less than obvious. Even less obvious was the
problem with unlimited polymorphic arrays, which required the use of the
'derived_array' argument of gfc_conv_derived_to_class because the code
looked just fine. Evidently, the convoluted casting in expressions like:
(integer(kind=4)[0:] * restrict) (*(void *[0:] *)
D.4413->_data.data)[S.61]->t.data
is the cause. I have seen this kind of problem with unlimited polymorphic
expressions previously. The fix re-renders them as:
(integer(kind=4)[0:] * restrict) (*(struct tuple[1] * restrict)
array.46.data)[S.47].t.data
Regtests on FC33/x86_64
OK for master (and maybe for 10-branch?)
Paul
Fortran: Fix memory problems with assumed rank formal args [PR98342].
2021-01-29 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/98342
* trans-expr.c (gfc_conv_derived_to_class): Add optional arg.
'derived_array' to hold the fixed, parmse expr in the case of
assumed rank formal arguments. Deal with optional arguments.
(gfc_conv_procedure_call): Null 'derived' array for each actual
argument. Add its address to the call to gfc_conv_derived_to_
class. Access the 'data' field of scalar descriptors before
deallocating allocatable components. Also strip NOPs before the
calls to gfc_deallocate_alloc_comp. Use 'derived' array as the
input to gfc_deallocate_alloc_comp if it is available.
* trans.h : Include the optional argument 'derived_array' to
the prototype of gfc_conv_derived_to_class. The default value
is NULL_TREE.
gcc/testsuite/
PR fortran/98342
* gfortran.dg/assumed_rank_20.f90 : New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: assumed_rank_20.f90
Type: text/x-fortran
Size: 2196 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20210129/d741221e/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: submit.diff
Type: text/x-patch
Size: 4368 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20210129/d741221e/attachment-0001.bin>
More information about the Fortran
mailing list