public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10075] Fortran: Fix for class defined operators [PR99125].
@ 2021-08-28 18:46 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-08-28 18:46 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4cecfae4b57e052008e2febe25607d5e2cad5dbb
commit r10-10075-g4cecfae4b57e052008e2febe25607d5e2cad5dbb
Author: Paul Thomas <pault@gcc.gnu.org>
Date: Sat Mar 13 11:39:57 2021 +0000
Fortran: Fix for class defined operators [PR99125].
2021-03-13 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/99125
* trans-array.c (gfc_conv_expr_descriptor): For deferred length
length components use the ss_info string length instead of
gfc_get_expr_charlen. Make sure that the deferred string length
is a variable before assigning to it. Otherwise use the expr.
* trans-expr.c (gfc_conv_string_length): Make sure that the
deferred string length is a variable before assigning to it.
gcc/testsuite/
PR fortran/99125
* gfortran.dg/alloc_deferred_comp_1.f90: New test.
(cherry picked from commit 7987beec679898cfa75839551d55ae5234a216bd)
Diff:
---
gcc/fortran/trans-array.c | 10 ++++++++--
gcc/fortran/trans-expr.c | 2 +-
gcc/testsuite/gfortran.dg/alloc_deferred_comp_1.f90 | 18 ++++++++++++++++++
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 46fd1dda4c4..c0a43c33613 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7722,15 +7722,21 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
/* Set the string_length for a character array. */
if (expr->ts.type == BT_CHARACTER)
{
- se->string_length = gfc_get_expr_charlen (expr);
+ if (deferred_array_component)
+ se->string_length = ss_info->string_length;
+ else
+ se->string_length = gfc_get_expr_charlen (expr);
+
if (VAR_P (se->string_length)
&& expr->ts.u.cl->backend_decl == se->string_length)
tmp = ss_info->string_length;
else
tmp = se->string_length;
- if (expr->ts.deferred)
+ if (expr->ts.deferred && VAR_P (expr->ts.u.cl->backend_decl))
gfc_add_modify (&se->pre, expr->ts.u.cl->backend_decl, tmp);
+ else
+ expr->ts.u.cl->backend_decl = tmp;
}
/* If we have an array section or are assigning make sure that
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index d88ad2b293a..cb901437965 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -2471,7 +2471,7 @@ gfc_conv_string_length (gfc_charlen * cl, gfc_expr * expr, stmtblock_t * pblock)
se.expr, build_zero_cst (TREE_TYPE (se.expr)));
gfc_add_block_to_block (pblock, &se.pre);
- if (cl->backend_decl)
+ if (cl->backend_decl && VAR_P (cl->backend_decl))
gfc_add_modify (pblock, cl->backend_decl, se.expr);
else
cl->backend_decl = gfc_evaluate_now (se.expr, pblock);
diff --git a/gcc/testsuite/gfortran.dg/alloc_deferred_comp_1.f90 b/gcc/testsuite/gfortran.dg/alloc_deferred_comp_1.f90
new file mode 100644
index 00000000000..0fc54d5331c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/alloc_deferred_comp_1.f90
@@ -0,0 +1,18 @@
+! { dg-do run }
+!
+! Test the fix for PR99125, where the array reference in the print
+! statement caused an ICE because the gimplifier complained about '0'
+! being used as an lvalue.
+!
+! Contributed by Gerhard Steinmetz <gscfq@t-online.de>
+!
+program p
+ type t
+ character(:), allocatable :: a(:)
+ end type
+ type(t) :: x
+ character(8) :: c(3) = ['12 45 78','23 56 89','34 67 90']
+ x%a = c
+ if (any (x%a(2:3) .ne. ['23 56 89','34 67 90'])) stop 1
+ if (any (x%a(2:3)(4:5) .ne. ['56','67'])) stop 2 ! Bizarrely this worked.
+end
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-28 18:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28 18:46 [gcc r10-10075] Fortran: Fix for class defined operators [PR99125] Harald Anlauf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).