diff options
author | Harald Anlauf <anlauf@gmx.de> | 2021-09-16 20:12:21 +0200 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2021-09-16 20:12:21 +0200 |
commit | cfea7b86f2430b9cb8018379b071f4004233119c (patch) | |
tree | cf0f208ec70d6b3318eaf216e2097968ba249308 /gcc/fortran/trans-expr.c | |
parent | db1a65d9364fe72c2fff65fb2dec051728b6f3fa (diff) | |
download | gcc-cfea7b86f2430b9cb8018379b071f4004233119c.zip gcc-cfea7b86f2430b9cb8018379b071f4004233119c.tar.gz gcc-cfea7b86f2430b9cb8018379b071f4004233119c.tar.bz2 |
Fortran - fix handling of optional allocatable DT arguments with INTENT(OUT)
gcc/fortran/ChangeLog:
PR fortran/102287
* trans-expr.c (gfc_conv_procedure_call): Wrap deallocation of
allocatable components of optional allocatable derived type
procedure arguments with INTENT(OUT) into a presence check.
gcc/testsuite/ChangeLog:
PR fortran/102287
* gfortran.dg/intent_out_14.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-expr.c')
-rw-r--r-- | gcc/fortran/trans-expr.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 18d6651..4a81f46 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -6548,6 +6548,17 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, // deallocate the components first tmp = gfc_deallocate_alloc_comp (fsym->ts.u.derived, parmse.expr, e->rank); + /* But check whether dummy argument is optional. */ + if (tmp != NULL_TREE + && fsym->attr.optional + && e->expr_type == EXPR_VARIABLE + && e->symtree->n.sym->attr.optional) + { + tree present; + present = gfc_conv_expr_present (e->symtree->n.sym); + tmp = build3_v (COND_EXPR, present, tmp, + build_empty_stmt (input_location)); + } if (tmp != NULL_TREE) gfc_add_expr_to_block (&se->pre, tmp); } |