From ca32d61bab85b4df400d463ff891e4f833bad8ec Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Mon, 17 Sep 2018 07:18:17 +0000 Subject: [PATCH] re PR fortran/85954 (ICE in make_ssa_name_fn, at tree-ssanames.c:266) 2018-09-17 Paul Thomas PR fortran/85954 * resolve.c (resolve_assoc_var): If the target expression is a deferred charlen dummy and the associate name shares the charlen, generate a new one. Make sure that new charlens are in the namespace list so that they get cleaned up. * trans-array.c (gfc_is_reallocatable_lhs): Associate names are not reallocatable. * trans-decl.c (gfc_get_symbol_decl): Put deferred character length dummy and result arrays on the deferred initialization list so that the variable length arrays can be correctly dealt with. * trans-expr.c (gfc_conv_string_length): Return if 'expr' is NULL rather than ICEing.. 2018-09-17 Paul Thomas PR fortran/85954 * gfortran.dg/deferred_character_21.f90 : New test. From-SVN: r264358 --- gcc/fortran/ChangeLog | 16 ++++++++++ gcc/fortran/resolve.c | 10 ++++++- gcc/fortran/trans-array.c | 3 ++ gcc/fortran/trans-decl.c | 7 +++++ gcc/fortran/trans-expr.c | 3 +- gcc/testsuite/ChangeLog | 5 ++++ .../gfortran.dg/deferred_character_21.f90 | 29 +++++++++++++++++++ 7 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/deferred_character_21.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 4c6c2445d1a..22435d3f0e0 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,19 @@ +2018-09-17 Paul Thomas + + PR fortran/85954 + * resolve.c (resolve_assoc_var): If the target expression is a + deferred charlen dummy and the associate name shares the + charlen, generate a new one. Make sure that new charlens are in + the namespace list so that they get cleaned up. + * trans-array.c (gfc_is_reallocatable_lhs): Associate names are + not reallocatable. + * trans-decl.c (gfc_get_symbol_decl): Put deferred character + length dummy and result arrays on the deferred initialization + list so that the variable length arrays can be correctly dealt + with. + * trans-expr.c (gfc_conv_string_length): Return if 'expr' is + NULL rather than ICEing.. + 2018-09-16 Janus Weil PR fortran/86484 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index ea0ce800743..e6180b889ec 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -8744,6 +8744,14 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target) if (!sym->ts.u.cl) sym->ts.u.cl = target->ts.u.cl; + if (sym->ts.deferred && target->expr_type == EXPR_VARIABLE + && target->symtree->n.sym->attr.dummy + && sym->ts.u.cl == target->ts.u.cl) + { + sym->ts.u.cl = gfc_new_charlen (sym->ns, NULL); + sym->ts.deferred = 1; + } + if (!sym->ts.u.cl->length && !sym->ts.deferred && target->expr_type == EXPR_CONSTANT) @@ -8756,7 +8764,7 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target) || sym->ts.u.cl->length->expr_type != EXPR_CONSTANT) && target->expr_type != EXPR_VARIABLE) { - sym->ts.u.cl = gfc_get_charlen(); + sym->ts.u.cl = gfc_new_charlen (sym->ns, NULL); sym->ts.deferred = 1; /* This is reset in trans-stmt.c after the assignment diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 473bfc5419b..9565b7d8dd9 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -9520,6 +9520,9 @@ gfc_is_reallocatable_lhs (gfc_expr *expr) sym = expr->symtree->n.sym; + if (sym->attr.associate_var) + return false; + /* An allocatable class variable with no reference. */ if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->attr.allocatable diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index eea6b81ebfa..e54d09817cc 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1510,6 +1510,13 @@ gfc_get_symbol_decl (gfc_symbol * sym) /* Dummy variables should already have been created. */ gcc_assert (sym->backend_decl); + /* However, the string length of deferred arrays must be set. */ + if (sym->ts.type == BT_CHARACTER + && sym->ts.deferred + && sym->attr.dimension + && sym->attr.allocatable) + gfc_defer_symbol_init (sym); + if (sym->attr.pointer && sym->attr.dimension && sym->ts.type != BT_CLASS) GFC_DECL_PTR_ARRAY_P (sym->backend_decl) = 1; diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 2596b8e151d..35052a8a8ea 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -2237,7 +2237,8 @@ gfc_conv_string_length (gfc_charlen * cl, gfc_expr * expr, stmtblock_t * pblock) if (!cl->length) { gfc_expr* expr_flat; - gcc_assert (expr); + if (!expr) + return; expr_flat = gfc_copy_expr (expr); flatten_array_ctors_without_strlen (expr_flat); gfc_resolve_expr (expr_flat); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 79ecbb7f61a..c40fc5f692c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-09-17 Paul Thomas + + PR fortran/85954 + * gfortran.dg/deferred_character_21.f90 : New test. + 2018-09-16 Janus Weil PR fortran/86484 diff --git a/gcc/testsuite/gfortran.dg/deferred_character_21.f90 b/gcc/testsuite/gfortran.dg/deferred_character_21.f90 new file mode 100644 index 00000000000..354c847556c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/deferred_character_21.f90 @@ -0,0 +1,29 @@ +! { dg-do compile } +! { dg-options "-O3" } +! +! Tests the fix for PR85954 in which the gimplifier could not determine +! the space required for the dummy argument data types, when inlining the +! subroutines. +! +! Contributed by G.Steinmetz +! +program p + character(kind=1,len=:), allocatable :: z(:) + allocate (z, source = ["xyz"]) + print *, allocated(z), size(z), len(z), z + call s(z) + call t(z) +contains + subroutine s(x) + character(kind=1,len=:), allocatable :: x(:) + x = ['abcd'] + print *, allocated(x), size(x), len(x), x + end + subroutine t(x) + character(kind=1,len=:), allocatable :: x(:) + associate (y => x) + y = ['abc'] + end associate + print *, allocated(x), size(x), len(x), x + end +end -- 2.30.2