[fortran] PR67740 - Wrong association status of allocatable character pointer in derived types
Checks
Commit Message
Hi All,
The title line of the PR should have been changed a long time since. As
noted in comment 5, the original problem was fixed in 10.5.
This patch fixes the problem described in comments 4 and 6, where the
hidden string length component was not being set in pointer assignment of
character arrays.
The fix regtests. OK for trunk and 13-branch?
Thanks are due to Harald for bringing this to my attention.
Paul
Fortran: Set hidden string length for pointer components [PR67440]
2023-10-11 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/pr67740
* trans-expr.cc (gfc_trans_pointer_assignment): Set the hidden
string length component for pointer assignment to character
pointer components.
gcc/testsuite/
PR fortran/87477
* gfortran.dg/pr67740.f90: New test
Comments
Hi Paul,
On 10/11/23 10:48, Paul Richard Thomas wrote:
> Hi All,
>
> The title line of the PR should have been changed a long time since. As
> noted in comment 5, the original problem was fixed in 10.5.
>
> This patch fixes the problem described in comments 4 and 6, where the
> hidden string length component was not being set in pointer assignment of
> character arrays.
>
> The fix regtests. OK for trunk and 13-branch?
this is OK for both.
I'd suggest to wait a couple of days or a week before backporting.
Thanks for the patch!
Harald
> Thanks are due to Harald for bringing this to my attention.
>
> Paul
>
> Fortran: Set hidden string length for pointer components [PR67440]
>
> 2023-10-11 Paul Thomas <pault@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/pr67740
> * trans-expr.cc (gfc_trans_pointer_assignment): Set the hidden
> string length component for pointer assignment to character
> pointer components.
>
> gcc/testsuite/
> PR fortran/87477
> * gfortran.dg/pr67740.f90: New test
>
Hi Paul,
the patch is fine, but I forgot the mention that the testcase needs fixing:
Instead of
! {dg-do compile }
you'll likely want
! { dg-do run }
(Note the space before the dg-command.)
Cheers,
Harald
On 10/11/23 21:06, Harald Anlauf wrote:
> Hi Paul,
>
> On 10/11/23 10:48, Paul Richard Thomas wrote:
>> Hi All,
>>
>> The title line of the PR should have been changed a long time since. As
>> noted in comment 5, the original problem was fixed in 10.5.
>>
>> This patch fixes the problem described in comments 4 and 6, where the
>> hidden string length component was not being set in pointer assignment of
>> character arrays.
>>
>> The fix regtests. OK for trunk and 13-branch?
>
> this is OK for both.
>
> I'd suggest to wait a couple of days or a week before backporting.
>
> Thanks for the patch!
>
> Harald
>
>> Thanks are due to Harald for bringing this to my attention.
>>
>> Paul
>>
>> Fortran: Set hidden string length for pointer components [PR67440]
>>
>> 2023-10-11 Paul Thomas <pault@gcc.gnu.org>
>>
>> gcc/fortran
>> PR fortran/pr67740
>> * trans-expr.cc (gfc_trans_pointer_assignment): Set the hidden
>> string length component for pointer assignment to character
>> pointer components.
>>
>> gcc/testsuite/
>> PR fortran/87477
>> * gfortran.dg/pr67740.f90: New test
>>
>
>
Hi Harald and Bernhard,
Indeed, you are right about the space. However, the compile is intentional.
This catches the fix:
! { dg-final { scan-tree-dump-times "co._data1_length = 10;" 1 "original" }
}
Also, it helps to get the PR number right!
I was rushing to get the patch out before leaving for work and so even more
error prone than usual....
Cheers
Paul
On Wed, 11 Oct 2023 at 20:21, Harald Anlauf <anlauf@gmx.de> wrote:
> Hi Paul,
>
> the patch is fine, but I forgot the mention that the testcase needs fixing:
>
> Instead of
>
> ! {dg-do compile }
>
> you'll likely want
>
> ! { dg-do run }
>
> (Note the space before the dg-command.)
>
> Cheers,
> Harald
>
> On 10/11/23 21:06, Harald Anlauf wrote:
> > Hi Paul,
> >
> > On 10/11/23 10:48, Paul Richard Thomas wrote:
> >> Hi All,
> >>
> >> The title line of the PR should have been changed a long time since. As
> >> noted in comment 5, the original problem was fixed in 10.5.
> >>
> >> This patch fixes the problem described in comments 4 and 6, where the
> >> hidden string length component was not being set in pointer assignment
> of
> >> character arrays.
> >>
> >> The fix regtests. OK for trunk and 13-branch?
> >
> > this is OK for both.
> >
> > I'd suggest to wait a couple of days or a week before backporting.
> >
> > Thanks for the patch!
> >
> > Harald
> >
> >> Thanks are due to Harald for bringing this to my attention.
> >>
> >> Paul
> >>
> >> Fortran: Set hidden string length for pointer components [PR67440]
> >>
> >> 2023-10-11 Paul Thomas <pault@gcc.gnu.org>
> >>
> >> gcc/fortran
> >> PR fortran/pr67740
> >> * trans-expr.cc (gfc_trans_pointer_assignment): Set the hidden
> >> string length component for pointer assignment to character
> >> pointer components.
> >>
> >> gcc/testsuite/
> >> PR fortran/87477
> >> * gfortran.dg/pr67740.f90: New test
> >>
> >
> >
>
>
@@ -10403,11 +10403,36 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, gfc_expr * expr2)
}
if (expr1->ts.type == BT_CHARACTER
- && expr1->symtree->n.sym->ts.deferred
- && expr1->symtree->n.sym->ts.u.cl->backend_decl
- && VAR_P (expr1->symtree->n.sym->ts.u.cl->backend_decl))
+ && expr1->ts.deferred)
{
- tmp = expr1->symtree->n.sym->ts.u.cl->backend_decl;
+ gfc_symbol *psym = expr1->symtree->n.sym;
+ tmp = NULL_TREE;
+ if (psym->ts.type == BT_CHARACTER)
+ {
+ gcc_assert (psym->ts.u.cl->backend_decl
+ && VAR_P (psym->ts.u.cl->backend_decl));
+ tmp = psym->ts.u.cl->backend_decl;
+ }
+ else if (expr1->ts.u.cl->backend_decl
+ && VAR_P (expr1->ts.u.cl->backend_decl))
+ tmp = expr1->ts.u.cl->backend_decl;
+ else if (TREE_CODE (lse.expr) == COMPONENT_REF)
+ {
+ gfc_ref *ref = expr1->ref;
+ for (;ref; ref = ref->next)
+ {
+ if (ref->type == REF_COMPONENT
+ && ref->u.c.component->ts.type == BT_CHARACTER
+ && gfc_deferred_strlen (ref->u.c.component, &tmp))
+ tmp = fold_build3_loc (input_location, COMPONENT_REF,
+ TREE_TYPE (tmp),
+ TREE_OPERAND (lse.expr, 0),
+ tmp, NULL_TREE);
+ }
+ }
+
+ gcc_assert (tmp);
+
if (expr2->expr_type != EXPR_NULL)
gfc_add_modify (&block, tmp,
fold_convert (TREE_TYPE (tmp), strlen_rhs));