[PATCH 1/4] openacc: Remove dereference for non-pointer derived-type members

Julian Brown julian@codesourcery.com
Thu Feb 4 13:58:26 GMT 2021


Hi Tobias,

Thanks for review! Comments below.

On Tue, 2 Feb 2021 17:32:03 +0100
Tobias Burnus <tobias@codesourcery.com> wrote:

> > diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
> > index 00358ca4d39..8d8da4593c3 100644
> > --- a/gcc/fortran/trans-openmp.c
> > +++ b/gcc/fortran/trans-openmp.c
> > @@ -3013,7 +3013,8 @@ gfc_trans_omp_clauses (stmtblock_t *block,
> > gfc_omp_clauses *clauses, }
> >   
> >   			  OMP_CLAUSE_DECL (node)
> > -			    = build_fold_indirect_ref (data);
> > +			    = (POINTER_TYPE_P (TREE_TYPE (data))
> > +			       ? build_fold_indirect_ref (data) :
> > data); OMP_CLAUSE_SIZE (node) = size;
> >   			  node2 = build_omp_clause
> > (input_location, OMP_CLAUSE_MAP);  
> 
> I am a bit surprised given that:
>                        if (sym_attr.pointer || (openacc &&
> sym_attr.allocatable))
> 
> I wonder whether we have a size problem:
>                                data = inner;
>                                size = TYPE_SIZE_UNIT (TREE_TYPE
> (inner));

I think the code was correct wrt. data sizes, but the logic was
admittedly rather convoluted. I think the attached is better -- the
essential "weirdness" of the previous patch is that it seemed like a
BT_DERIVED-typed "inner" could either be a pointer or not, and likewise
for the BT_CLASS case.

Actually though, that wasn't true. All the non-POINTER_TYPE_P cases
involve BT_DERIVED, because the decl is transparently dereferenced
by the earlier gfc_conv_component_ref call. BT_CLASS pointers, however,
were not dereferenced -- so "data" appeared as an actual pointer. The
pre-patch code actually only worked in the BT_CLASS case.

So, I think the new version makes more sense. (The "size" field is
either transparently dereferenced via gfc_conv_component_ref, or comes
from the class's vtable, so it's never the size of the non-dereferenced
pointer.)

Re-tested with offloading to AMD GCN. OK?

Thank you,

Julian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-openacc-Dereference-BT_CLASS-data-pointers-but-not-B.patch
Type: text/x-patch
Size: 5733 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210204/7d84e77b/attachment-0001.bin>


More information about the Gcc-patches mailing list