https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113377

--- Comment #7 from anlauf at gcc dot gnu.org ---
(In reply to Mikael Morin from comment #6)
> (In reply to anlauf from comment #4)
> > 
> > Note that the following scalar example also fails:
> > 
> "Fortunately", it is invalid.  :-)
> 
> From 15.5.2.12 (Argument presence and restrictions on arguments not present):
> 
> An optional dummy argument that is not present is subject to the following
> restrictions.
> (...)
>   (8) If it is allocatable, it shall not be allocated, deallocated, or
> supplied as an actual argument corresponding to an optional nonallocatable
> dummy argument.
> 
> In comment #4, j from one is non-present, allocatable, optional and passed
> to j from two which is optional nonallocatable.

Thanks for clarifying this.  This helps to reduce the testcases I am looking
at.

For the next step, I've actually stepped back a little: it helps to fix
the non-elemental cases first.  I am currently working with:

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 9dd1f4086f4..52fdbd5ca66 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -6526,6 +6648,10 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
                            gfc_init_se (&argse, NULL);
                            argse.want_pointer = 1;
                            gfc_conv_expr (&argse, e);
+                           if (e->symtree->n.sym->attr.dummy
+                               && POINTER_TYPE_P (TREE_TYPE (argse.expr)))
+                             argse.expr = gfc_build_addr_expr (NULL_TREE,
+                                                               argse.expr);
                            cond = fold_convert (TREE_TYPE (argse.expr),
                                                 null_pointer_node);
                            cond = fold_build2_loc (input_location, NE_EXPR,
@@ -7256,6 +7382,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
              && e->symtree->n.sym->attr.optional
              && (((e->rank != 0 && elemental_proc)
                   || e->representation.length || e->ts.type == BT_CHARACTER
+                  || (e->rank == 0 && fsym && fsym->as == NULL)
                   || (e->rank != 0
                       && (fsym == NULL
                           || (fsym->as

I'll attach a testcase exercising this for integer dummies, but I have a
full set for other types at hand.

Reply via email to