This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, fortran] PR34640 - ICE when assigning item of a derived-component to a pointer


Dear All,

Encouraged by the response to the earlier version of the patch, please
find attached the final version that includes the promised cleanup;
except for the libgomp problem for which the fix remains the same.

Please find some descriptive material in the original submission below.

Two parts of the patch, most notably the new function
trans-array.c(gfc_get_descriptor_offsets_for_info), replace bits of
code that broke the API for access to array descriptor fields. Thanks
to Andre for spotting one of the sources of this API breaking, which
cost me a lot of time.

I presume that the module version number has to be bumped up?

Bootstraps and regtests on FC23/x86_64 - OK for trunk?

Regards

Paul

2017-07-01  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/34640
    PR fortran/40737
    PR fortran/55763
    PR fortran/57019
    PR fortran/57116

    * trans-array.c: Add SPAN_FIELD and update indices for
    subsequent fields.
    (gfc_conv_descriptor_span, gfc_conv_descriptor_span_get,
    gfc_conv_descriptor_span_set, is_pointer_array,
    get_array_span): New functions.
    (gfc_get_descriptor_offsets_for_info): New function to preserve
    API for access to descriptor fields for trans-types.c.
    (gfc_conv_scalarized_array_ref): If the expression is a subref
    array, make sure that info->descriptor is a descriptor type.
    Otherwise, if info->descriptor is a pointer array, set 'decl'
    and fix it if it is a component reference.
    (build_array_ref): Simplify handling of class array refs by
    passing the vptr to gfc_build_array_ref rather than generating
    the pointer arithmetic in this function.
    (gfc_conv_array_ref): As in gfc_conv_scalarized_array_ref, set
    'decl'.
    (gfc_array_allocate): Set the span field if this is a pointer
    array.
    (gfc_conv_expr_descriptor): Set the span field for pointer
    assignments.
    * trans-array.h: Prototypes for gfc_conv_descriptor_span_get
    gfc_conv_descriptor_span_set and
    gfc_get_descriptor_offsets_for_info added.
    * trans.c (get_array_span): New function.
    (gfc_build_array_ref): Simplify by calling get_array_span and
    obtain 'span' if 'decl' or 'vptr' present.
    trans-decl.c (gfc_get_symbol_decl): If a non-class pointer
    array, mark the declaration as a GFC_DECL_PTR_ARRAY_P. Remove
    the setting of GFC_DECL_SPAN.
    (gfc_trans_deferred_vars): Set the span field to zero in thge
    originating scope.
    * trans-expr.c (gfc_trans_pointer_assignment): Remove code for
    setting of GFC_DECL_SPAN. Set the 'span' field for non-class
    pointers to class function results. Likewise for rank remap.
    * trans.h : Rename DECL_LANG_FLAG_6, GFC_DECL_SUBREF_ARRAY_P,
    as GFC_DECL_PTR_ARRAY_P.
    * trans-intrinsic.c (conv_expr_ref_to_caf_ref): Pick up the
    'token' offset from the field decl in the descriptor.
    (conv_isocbinding_subroutine): Set the 'span' field.
    * trans-io.c (gfc_trans_transfer): Always scalarize pointer
    array io.
    * trans-stmt.c (trans_associate_var): Set the 'span' field.
    * trans-types.c (gfc_get_array_descriptor_base): Add the 'span'
    field to the array descriptor.
    (gfc_get_derived_type): Pointer array components are marked as
    GFC_DECL_PTR_ARRAY_P.
    (gfc_get_array_descr_info): Replaced API breaking code for
    descriptor offset calling gfc_get_descriptor_offsets_for_info.


2017-07-01  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/34640
    * gfortran.dg/assumed_type_2.f90: Adjust some of the tree dump
    checks.
    * gfortran.dg/no_arg_check_2.f90: Likewise.
    * gfortran.dg/pointer_array_1.f90: New test.
    * gfortran.dg/pointer_array_2.f90: New test.
    * gfortran.dg/pointer_array_component_1.f90: New test.
    * gfortran.dg/pointer_array_component_2.f90: New test.
    * gfortran.dg/goacc/kernels-alias-4.f95: Bump up both tree scan
    counts by 1.

    PR fortran/40737
    * gfortran.dg/pointer_array_3.f90: New test.

    PR fortran/57116
    * gfortran.dg/pointer_array_4.f90: New test.

    PR fortran/55763
    * gfortran.dg/pointer_array_5.f90: New test.

    PR fortran/57019
    * gfortran.dg/pointer_array_6.f90: New test.

2017-07-01  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/34640
    * libgfortran/libgfortran.h: Add span field to descriptor.

On 24 June 2017 at 11:48, Paul Richard Thomas
<paul.richard.thomas@gmail.com> wrote:
> Dear All,
>
> Please find attached a draft patch for the above PR, together with PRs
> 40737, 55763, 57019 and 57116. These PRs constitute problems
> associated with the last F95 feature that gfortran does not completely
> implement.
>
> I want to sound out if this is acceptable as the way to fix these
> problems before going to the trouble of doing the final clean up;
> especially of trans.c (gfc_build_array_ref) and
> trans-array.c(build_array_ref).
>
> The problem concerns pointers to derived type array components. eg:
> pointer_array(:) => derived_array (:)%component
>
> At present gfortran uses a rather crude fix, where a 'span' variable
> with value of sizeof(element of derived_array) is used for pointer
> arithmetic to access elements of the array;
> &pointer_array(i) = &derived_array(1)%component + span*(i-1)
>
> The difficulty of using a variable 'span' is that it is not passed to
> procedures and it is not available to array pointer components. This
> patch fixes this by the introduction of a span field in the array
> descriptor. Note that this is only used for intrinsic type, pointer
> arrays in this version of the patch. A considerable simplification
> would arise from using the span field in class arrays too. This might
> well be one result of the clean up mentioned above.
>
> Tobias Burnus and I have been putting off fixing these PRs for a long
> time because of the pending array descriptor reform. However, work on
> fortran-dev has once again stopped and neither I nor, I think, anybody
> else has the time to restart this work anytime soon.
>
> pointer[1,2].f90 in the libgomp testsuite fail if this modification to
> array referencing is exposed to them. For the time being,
> trans-array.c(is_pointer_array) has:
> +   if (flag_openmp)
> +     return false;
> to switch off the modification. I will come back to this during the
> clean up, with the hope of putting it right.
>
> Bootstraps and regtests on FC23/x86_64 - OK to proceed to completion
> and submission?
>
> Paul
>
>
> 2017-06-24  Paul Thomas  <pault@gcc.gnu.org>
>
>     PR fortran/34640
>     PR fortran/40737
>     PR fortran/55763
>     PR fortran/57019
>     PR fortran/57116
>
>     * trans-array.c: Add SPAN_FIELD and update indices for
>     subsequent fields.
>     (gfc_conv_descriptor_span, gfc_conv_descriptor_span_get,
>     gfc_conv_descriptor_span_set, is_pointer_array,
>     get_array_span): New functions.
>     (gfc_conv_scalarized_array_ref): If the expression is a subref
>     array, make sure that info->descriptor is a descriptor type.
>     Otherwise, if info->descriptor is a pointer array, set 'decl'
>     and fix it if it is a component reference.
>     (gfc_conv_array_ref): Similarly set 'decl'.
>     (gfc_array_allocate): Set the span field if this is a pointer
>     array.
>     (gfc_conv_expr_descriptor): Set the span field for pointer
>     assignments.
>     * trans-array.h: Prototypes for gfc_conv_descriptor_span_get
>     and gfc_conv_descriptor_span_set added.
>     * trans.c (gfc_build_array_ref): GFC_DECL_SUBREF_ARRAY_P change
>     to GFC_DECL_PTR_ARRAY_P and defreference if a PARM_DECL.
>     trans-decl.c (gfc_get_symbol_decl): If a non-class pointer
>     array, mark the declaration as a GFC_DECL_PTR_ARRAY_P. Remove
>     the setting of GFC_DECL_SPAN.
>     (gfc_trans_deferred_vars): Set the span field to zero in the
>     originating scope.
>     * trans-expr.c (gfc_trans_pointer_assignment): Remove code for
>     setting of GFC_DECL_SPAN. Set the 'span' field for non-class
>     pointers to class function results. Likewise for rank remap.
>     * trans.h : Rename DECL_LANG_FLAG_6, GFC_DECL_SUBREF_ARRAY_P,
>     as GFC_DECL_PTR_ARRAY_P.
>     * trans-intrinsic.c (conv_expr_ref_to_caf_ref): Pick up the
>     'token' offset from the field decl in the descriptor.
>     (conv_isocbinding_subroutine): Set the 'span' field.
>     * trans-io.c (gfc_trans_transfer): Always scalarize pointer
>     array io.
>     * trans-stmt.c (trans_associate_var): Set the 'span' field.
>     * trans-types.c (gfc_get_array_descriptor_base): Add the 'span'
>     field to the array descriptor.
>     (gfc_get_derived_type): Pointer array components are marked as
>     GFC_DECL_PTR_ARRAY_P.
>     (gfc_get_array_descr_info): Jump one more in the DECL_CHAIN to
>     access the offset field.
>
>
> 2017-06-24  Paul Thomas  <pault@gcc.gnu.org>
>
>     PR fortran/34640
>     * gfortran.dg/assumed_type_2.f90: Adjust some of the tree dump
>     checks.
>     * gfortran.dg/no_arg_check_2.f90: Likewise.
>     * gfortran.dg/pointer_array_1.f90: New test.
>     * gfortran.dg/pointer_array_2.f90: New test.
>     * gfortran.dg/pointer_array_component_1.f90: New test.
>     * gfortran.dg/pointer_array_component_2.f90: New test.
>     * gfortran.dg/goacc/kernels-alias-4.f95: Bump up both tree scan
>     counts by 1.
>
>     PR fortran/40737
>     * gfortran.dg/pointer_array_3.f90: New test.
>
>     PR fortran/57116
>     * gfortran.dg/pointer_array_4.f90: New test.
>
>     PR fortran/55763
>     * gfortran.dg/pointer_array_5.f90: New test.
>
>     PR fortran/57019
>     * gfortran.dg/pointer_array_6.f90: New test.
>
> 2017-06-24  Paul Thomas  <pault@gcc.gnu.org>
>
>     PR fortran/34640
>     * libgfortran/libgfortran.h: Add span field to descriptor.
>
>
> --
> "If you can't explain it simply, you don't understand it well enough"
> - Albert Einstein



-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein

Attachment: submit0107.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]