diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2020-08-28 13:54:10 +0200 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2020-08-28 13:54:10 +0200 |
commit | cb3c3d63315ceb4dc262e5efb83b42c73c43387d (patch) | |
tree | a31c6b5ab69e7883905bc4591157d059fefc8382 /gcc/fortran/trans-array.c | |
parent | b648814c02eb418aaf27897c480452172ee96303 (diff) | |
download | gcc-cb3c3d63315ceb4dc262e5efb83b42c73c43387d.zip gcc-cb3c3d63315ceb4dc262e5efb83b42c73c43387d.tar.gz gcc-cb3c3d63315ceb4dc262e5efb83b42c73c43387d.tar.bz2 |
Fortran: Fix absent-optional handling for nondescriptor arrays (PR94672)
gcc/fortran/ChangeLog:
PR fortran/94672
* trans-array.c (gfc_trans_g77_array): Check against the parm decl and
set the nonparm decl used for the is-present check to NULL if absent.
gcc/testsuite/ChangeLog:
PR fortran/94672
* gfortran.dg/optional_assumed_charlen_2.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-array.c')
-rw-r--r-- | gcc/fortran/trans-array.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 0e3495d..6566c47 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -6472,8 +6472,14 @@ gfc_trans_g77_array (gfc_symbol * sym, gfc_wrapped_block * block) if (sym->attr.optional || sym->attr.not_always_present) { - tmp = gfc_conv_expr_present (sym); - stmt = build3_v (COND_EXPR, tmp, stmt, build_empty_stmt (input_location)); + tree nullify; + if (TREE_CODE (parm) != PARM_DECL) + nullify = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, + parm, null_pointer_node); + else + nullify = build_empty_stmt (input_location); + tmp = gfc_conv_expr_present (sym, true); + stmt = build3_v (COND_EXPR, tmp, stmt, nullify); } gfc_add_init_cleanup (block, stmt, NULL_TREE); |