[PATCH] deferred-shape vs assumed-shape

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] deferred-shape vs assumed-shape

gcc - fortran mailing list
See
https://stackoverflow.com/questions/60972134/whats-wrong-with-the-following-fortran-code-gfortran-dtio-dummy-argument-at

Is A(:) a deferred-shape array or an assumed-shape array?  The
answer of course depends on context.

This patch fixes the issue found at the above URL.

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c (revision 280157)
+++ gcc/fortran/interface.c (working copy)
@@ -4916,10 +4916,15 @@ check_dtio_arg_TKR_intent (gfc_symbol *fsym, bool type
   || ((type != BT_CLASS) && fsym->attr.dimension)))
     gfc_error ("DTIO dummy argument at %L must be a scalar",
        &fsym->declared_at);
-  else if (rank == 1
-   && (fsym->as == NULL || fsym->as->type != AS_ASSUMED_SHAPE))
-    gfc_error ("DTIO dummy argument at %L must be an "
-       "ASSUMED SHAPE ARRAY", &fsym->declared_at);
+  else if (rank == 1)
+    {
+      if (fsym->as == NULL
+  || !(fsym->as->type == AS_ASSUMED_SHAPE
+ || (fsym->as->type == AS_DEFERRED && fsym->attr.dummy
+    && !fsym->attr.allocatable && !fsym->attr.pointer)))
+ gfc_error ("DTIO dummy argument at %L must be an "
+   "ASSUMED-SHAPE ARRAY", &fsym->declared_at);
+    }
 
   if (type == BT_CHARACTER && fsym->ts.u.cl->length != NULL)
     gfc_error ("DTIO character argument at %L must have assumed length",

--
Steve
Reply | Threaded
Open this post in threaded view
|

[Patch][Fortran] Resolve formal args before checking DTIO (was: Re: [PATCH] deferred-shape vs assumed-shape)

Tobias Burnus-3
Hi Steve,

I think your patch is fine - however, I think calling the normal
resolve_formal_arglist looks a bit cleaner to me (as done in the
attached patch). — Additionally, I added the testcase.

Side effect of my variant is that gfc_check_dtio_interfaces will
be called again a bit later again. — In this sense, Steve's patch,
which replicates a chunk of resolve_formal_arglist, is better.

Thoughts by anyone?

OK?

Tobias

PS: I was thinking of calling resolve_symbol instead
but this one does not resolve the formal arguments
(via "gfc_resolve (sym->formal_ns)") as sym->attr.contained.

On 4/1/20 10:04 PM, Steve Kargl via Fortran wrote:

> See
> https://stackoverflow.com/questions/60972134/whats-wrong-with-the-following-fortran-code-gfortran-dtio-dummy-argument-at
>
> Is A(:) a deferred-shape array or an assumed-shape array?  The
> answer of course depends on context.
>
> This patch fixes the issue found at the above URL.
>
> Index: gcc/fortran/interface.c
> ===================================================================
> --- gcc/fortran/interface.c   (revision 280157)
> +++ gcc/fortran/interface.c   (working copy)
> @@ -4916,10 +4916,15 @@ check_dtio_arg_TKR_intent (gfc_symbol *fsym, bool type
>         || ((type != BT_CLASS) && fsym->attr.dimension)))
>       gfc_error ("DTIO dummy argument at %L must be a scalar",
>              &fsym->declared_at);
> -  else if (rank == 1
> -        && (fsym->as == NULL || fsym->as->type != AS_ASSUMED_SHAPE))
> -    gfc_error ("DTIO dummy argument at %L must be an "
> -            "ASSUMED SHAPE ARRAY", &fsym->declared_at);
> +  else if (rank == 1)
> +    {
> +      if (fsym->as == NULL
> +       || !(fsym->as->type == AS_ASSUMED_SHAPE
> +             || (fsym->as->type == AS_DEFERRED && fsym->attr.dummy
> +                 && !fsym->attr.allocatable && !fsym->attr.pointer)))
> +     gfc_error ("DTIO dummy argument at %L must be an "
> +                "ASSUMED-SHAPE ARRAY", &fsym->declared_at);
> +    }
>
>     if (type == BT_CHARACTER && fsym->ts.u.cl->length != NULL)
>       gfc_error ("DTIO character argument at %L must have assumed length",
>
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

dtio.diff (5K) Download Attachment