https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129272
--- Comment #10 from Harald Anlauf <anlauf at gcc dot gnu.org> ---
(In reply to Harald Anlauf from comment #9)
> (In reply to Steve Kargl from comment #6)
> > This patch fixes the ICE during compilation. I haven't
> > written a executable test, but I suspect it will
> > segfault with an unallocated allocatable variable.
> > (Note copy-n-paste tab corruption likely).
> >
> > diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
> > index 8afa33cbc84..d0ffd9037a3 100644
> > --- a/gcc/fortran/trans-intrinsic.cc
> > +++ b/gcc/fortran/trans-intrinsic.cc
> > @@ -13506,9 +13506,13 @@ conv_intrinsic_move_alloc (gfc_code *code)
> > {
> > if (arg->expr)
> > {
> > - if (!strcmp ("stat", arg->name))
> > + if ((arg->name && strcmp ("stat", arg->name) == 0)
> > + || (arg->expr->symtree
> > + && !strcmp ("stat", arg->expr->symtree->name)))
> > tmp_sync_stat.stat = arg->expr;
> > - else if (!strcmp ("errmsg", arg->name))
> > + else if ((arg->name && strcmp ("errmsg", arg->name) == 0)
> > + || (arg->expr->symtree
> > + && !strcmp ("errmsg", arg->expr->symtree->name)))
> > tmp_sync_stat.errmsg = arg->expr;
> > }
> > arg = arg->next;
>
> Alternatively the following untested patch might work:
>
> diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc
> index b9f0fd0f085..c58f90abaa4 100644
> --- a/gcc/fortran/intrinsic.cc
> +++ b/gcc/fortran/intrinsic.cc
> @@ -4763,6 +4763,9 @@ do_sort:
>
> set_intrinsic_dummy_arg (a->associated_dummy, f);
>
> + if (a->name == NULL)
> + a->name = a->associated_dummy->u.intrinsic->name;
> +
> if (actual == NULL)
> *ap = a;
> else
Both patches above are wrong: the first uses the name of the variable, not
the name of the optional dummy; the second regresses on several testcase
even if the assignment is protected by if (f->optional).
The following works:
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 8afa33cbc84..92f2521d650 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -13506,9 +13506,9 @@ conv_intrinsic_move_alloc (gfc_code *code)
{
if (arg->expr)
{
- if (!strcmp ("stat", arg->name))
+ if (!strcmp ("stat", arg->associated_dummy->u.intrinsic->name))
tmp_sync_stat.stat = arg->expr;
- else if (!strcmp ("errmsg", arg->name))
+ else if (!strcmp ("errmsg",
arg->associated_dummy->u.intrinsic->name))
tmp_sync_stat.errmsg = arg->expr;
}
arg = arg->next;