[Patch, fortran] PR29396 PR29606 PR30625 and PR30871 - subreference array pointers.

Paul Thomas paulthomas2@wanadoo.fr
Sun Sep 9 18:54:00 GMT 2007

:ADDPATCH fortran:

This is a first stab at fixing these beasts.  I would be the first to 
admit that this might not be the most efficient way of going about  the 
job but it does leave the rest of gfortran's functionality untouched.  
Also, the patch is incomplete.  Pointer references to substrings of 
components of arrays of derived types do not work and, without having 
tried it, I am sure that WHERE and FORALL masks will do odd things if 
they are such pointers.  The former is something that I will work on 
right away, after writing a PR, and the latter is a longer term TODO.

The patch functions by adding a 'span' field to the lang_decl structure, 
which stores the size of the target array elements.  The rhs of a 
pointer assignment is converted to a descriptor, whose data pointer is 
to the subreference of the first element of the array.  
gfc_build_array_ref has then been modified to take a look at the 
declaration for the array; if it is a pointer to a subreference array, 
the offset is calculated in bytes and the element extracted by explicit 
pointer arithmetic.  The treatment of these pointers as actual arguments 
is very conservative - they are always copy-in/copy-out.  Doubtless 
cleverer things can be done in teh fullness of time.

At present, very few references to gfc_build_array_ref have been updated 
to supply the variable declaration.  However, these are sufficient to 
provide the basic functionality.  I am rather sure that the problem with 
substrings of components, mentioned above, lies in resolve.c.  However, 
I just do not have time to deal with it now.

The testcase is an amalgam of the PR testcases, together with some 
testing that the target is modified as it should be and that various 
forms of pointer reference work correctly.

It is my opinion that this patch is ready for 4.3 simply because it 
provides an extra functionality that is ringfenced by specific tests.  
Such pointer assignements, at present, either lead to ICEs or wrong 
code.  Hence, even if it is not in its final form, it will not break 
anything, whilst filling in the missing f95 feature.

Regtested on Cygwin_NT/amd64 - OK for trunk..... before 09/10 :-) ?


2007-09-09  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/29396
    PR fortran/29606
    PR fortran/30625
    PR fortran/30871
    * trans.h : Add extra argument to gfc_build_array_ref. Rename
    gfc_conv_aliased_arg to gfc_conv_subref_array_arg.  Move
    prototype of is_aliased_array to gfortran.h and rename it
    is_subref_array.  Add field span to lang_decl, add a new
    decl lang specific flag accessed by GFC_DECL_SUBREF_ARRAY_P
    and a new type flag GFC_DECL_SUBREF_ARRAY_P.
    * trans.c (gfc_build_array_ref): Add the new argument, decl.
    If this is a subreference array pointer, use the lang_decl
    field 'span' to claculate the offset in bytes and use pointer
    arithmetic to access the element.
    * trans-array.c (gfc_conv_scalarized_array_ref,
    gfc_conv_array_ref): Add the backend declaration as the third
    field, if it is likely to be a subreference array pointer.
    For all other references to gfc_build_array_ref, set the third
    argument to NULL.
    (gfc_conv_expr_descriptor): If the rhs of a pointer assignment
    is a subreference array, then calculate the offset to the
    subreference of the first element and set the descriptor data
    pointer to this.
    trans-expr.c (gfc_get_expr_charlen): Use the symbol charlen if
    a character subreference gets through.
    (gfc_conv_aliased_arg): Rename to gfc_conv_subref_array_arg.
    (is_aliased_array): Remove.
    (gfc_conv_function_call): Change reference to is_aliased_array
    to is_subref_array.
    (gfc_trans_pointer_assignment): Add the array element length to
    the lang_decl 'span' field.
    * gfortran.h : Add subref_array_pointer to symbol_attribute and
    add the prototype for is_subref_array.
    * trans-stmt.c : Add NULL for third argument in all references
    to gfc_build_array_ref.
    * expr.c (is_subref_array): Renamed copy of is_aliased_array.
    If this is a subreference array pointer, return true.
    (gfc_check_pointer_assign): If the rhs is a subreference array,
    set the lhs subreference_array_pointer attribute.
    * trans-decl.c (gfc_get_symbol_decl): Allocate the lang_decl
    field if the symbol is a subreference array pointer and set an
    initial value of zero for the 'span' field.
    * trans-io.c (set_internal_unit): Refer to is_subref_array and
    (nml_get_addr_expr): Add NULL third argument to
    (gfc_trans_transfer): Use the scalarizer for a subreference

2007-09-09  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/29396
    PR fortran/29606
    PR fortran/30625
    PR fortran/30871
    * gfortran.dg/subref_array_pointer_1.f90: New test.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: submit.diff
Type: text/x-patch
Size: 36046 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070909/6c42146a/attachment.bin>

More information about the Gcc-patches mailing list