From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1431) id 19428385800C; Mon, 28 Dec 2020 15:16:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19428385800C MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Paul Thomas To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-9136] This patch fixes PRs 96100 and 96101. X-Act-Checkin: gcc X-Git-Author: Paul Thomas X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: f7c9f203a73a311d01fdb44f8bf47f6bf99bb02e X-Git-Newrev: 9db58db5b3986531475968dd383f13a3f925d7ae Message-Id: <20201228151658.19428385800C@sourceware.org> Date: Mon, 28 Dec 2020 15:16:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Dec 2020 15:16:58 -0000 https://gcc.gnu.org/g:9db58db5b3986531475968dd383f13a3f925d7ae commit r9-9136-g9db58db5b3986531475968dd383f13a3f925d7ae Author: Paul Thomas Date: Thu Aug 20 18:17:59 2020 +0100 This patch fixes PRs 96100 and 96101. 2020-08-20 Paul Thomas gcc/fortran PR fortran/96100 PR fortran/96101 * trans-array.c (get_array_charlen): Tidy up the evaluation of the string length for array constructors. Avoid trailing array references. Ensure string lengths of deferred length components are set. For parentheses operator apply string length to both the primary expression and the enclosed expression. gcc/testsuite/ PR fortran/96100 PR fortran/96101 * gfortran.dg/char_length_23.f90: New test. (cherry picked from commit 300ef2fcc10e98359d14654be23bbb84a5d141e1) Diff: --- gcc/fortran/trans-array.c | 21 +++++++++++++++++++-- gcc/testsuite/gfortran.dg/char_length_23.f90 | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 572455e0d59..f5407956d63 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -7009,7 +7009,12 @@ get_array_charlen (gfc_expr *expr, gfc_se *se) e = gfc_constructor_first (expr->value.constructor)->expr; gfc_init_se (&tse, NULL); + + /* Avoid evaluating trailing array references since all we need is + the string length. */ if (e->rank) + tse.descriptor_only = 1; + if (e->rank && e->expr_type != EXPR_VARIABLE) gfc_conv_expr_descriptor (&tse, e); else gfc_conv_expr (&tse, e); @@ -7027,14 +7032,26 @@ get_array_charlen (gfc_expr *expr, gfc_se *se) gfc_add_modify (&se->pre, expr->ts.u.cl->backend_decl, tse.string_length); + /* Make sure that deferred length components point to the hidden + string_length component. */ + if (TREE_CODE (tse.expr) == COMPONENT_REF + && TREE_CODE (tse.string_length) == COMPONENT_REF + && TREE_OPERAND (tse.expr, 0) == TREE_OPERAND (tse.string_length, 0)) + e->ts.u.cl->backend_decl = expr->ts.u.cl->backend_decl; + return; case EXPR_OP: get_array_charlen (expr->value.op.op1, se); - /* For parentheses the expression ts.u.cl is identical. */ + /* For parentheses the expression ts.u.cl should be identical. */ if (expr->value.op.op == INTRINSIC_PARENTHESES) - return; + { + if (expr->value.op.op1->ts.u.cl != expr->ts.u.cl) + expr->ts.u.cl->backend_decl + = expr->value.op.op1->ts.u.cl->backend_decl; + return; + } expr->ts.u.cl->backend_decl = gfc_create_var (gfc_charlen_type_node, "sln"); diff --git a/gcc/testsuite/gfortran.dg/char_length_23.f90 b/gcc/testsuite/gfortran.dg/char_length_23.f90 new file mode 100644 index 00000000000..e9ddbc7b8fd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_length_23.f90 @@ -0,0 +1,25 @@ +! { dg-do compile } +! +! Test the fix for PRs 96100 and 96101. +! +! Contributed by Gerhardt Steinmetz +! +program p + type t + character(:), allocatable :: c(:) + end type + type(t) :: x + character(:), allocatable :: w + +! PR96100 + allocate(x%c(2), source = 'def') + associate (y => [x%c(1:1)]) ! ICE + print *,y + end associate + +! PR96101 + associate (y => ([w(:)])) + print *, y ! ICE + end associate + +end