From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F38FF385840D; Fri, 19 Jan 2024 21:16:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F38FF385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705699005; bh=NarUya8JZTVzLjzmU8w/QsllRHNltqHHkrdNcteAMgE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PppZox8ky4zwsWe/VcPbuWvL8FoPSgigH+ka05VoffTonYY5TYV74qGXiQ5zJMiRO TL4WnxjTokhG5HJz+GoWQTLXQw1uxO/naXGN3vLGySxRXzHvp6cNHrXuHPcu4nqN45 Vpq64wWG7Ebn/OIc838Oop6koiceM77FE9sRRl0I= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/113377] Wrong code passing optional dummy argument to elemental procedure with optional dummy Date: Fri, 19 Jan 2024 21:16:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113377 --- Comment #7 from anlauf at gcc dot gnu.org --- (In reply to Mikael Morin from comment #6) > (In reply to anlauf from comment #4) > >=20 > > Note that the following scalar example also fails: > >=20 > "Fortunately", it is invalid. :-) >=20 > From 15.5.2.12 (Argument presence and restrictions on arguments not prese= nt): >=20 > 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. >=20 > 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 * s= ym, gfc_init_se (&argse, NULL); argse.want_pointer =3D 1; gfc_conv_expr (&argse, e); + if (e->symtree->n.sym->attr.dummy + && POINTER_TYPE_P (TREE_TYPE (argse.expr))) + argse.expr =3D gfc_build_addr_expr (NULL_TREE, + argse.expr); cond =3D fold_convert (TREE_TYPE (argse.expr), null_pointer_node); cond =3D fold_build2_loc (input_location, NE_EX= PR, @@ -7256,6 +7382,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sy= m, && e->symtree->n.sym->attr.optional && (((e->rank !=3D 0 && elemental_proc) || e->representation.length || e->ts.type =3D=3D BT_CHAR= ACTER + || (e->rank =3D=3D 0 && fsym && fsym->as =3D=3D NULL) || (e->rank !=3D 0 && (fsym =3D=3D NULL || (fsym->as I'll attach a testcase exercising this for integer dummies, but I have a full set for other types at hand.=