From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4C4C43858415; Mon, 13 Sep 2021 20:55:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C4C43858415 From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines. Date: Mon, 13 Sep 2021 20:55:59 +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: 9.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Sep 2021 20:55:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102287 anlauf at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |anlauf at gcc dot gnu.org --- Comment #2 from anlauf at gcc dot gnu.org --- We need to wrap the deallocation of INTENT(out) allocatable components into a test for presence, like: diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 18d665192f0..076cffdd77f 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -6548,6 +6548,19 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * s= ym, // deallocate the components first tmp =3D gfc_deallocate_alloc_comp (fsym->ts.u.derived, parmse.expr, e->rank); + /* But check whether dummy argument is optional. */ + if (tmp !=3D NULL_TREE + && fsym->attr.optional + && e->expr_type =3D=3D EXPR_VARIABLE + && e->symtree->n.sym->attr.optional) + { + tree present, notpres; + present =3D gfc_conv_expr_present (e->symtree->n.sy= m); + notpres =3D build_empty_stmt (input_location); + tmp =3D fold_build3_loc (input_location, COND_EXPR, + void_type_node, + present, tmp, notpres); + } if (tmp !=3D NULL_TREE) gfc_add_expr_to_block (&se->pre, tmp); }=