public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-9201] Fortran: Fix deferred character lengths in array constructors [PR93833].
@ 2021-01-25  8:56 Paul Thomas
  0 siblings, 0 replies; only message in thread
From: Paul Thomas @ 2021-01-25  8:56 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f6adbc3702edb4b6931731282fe4b2350eba1e0d

commit r9-9201-gf6adbc3702edb4b6931731282fe4b2350eba1e0d
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue Dec 29 17:37:25 2020 +0000

    Fortran: Fix deferred character lengths in array constructors [PR93833].
    
    2020-12-29  Paul Thomas  <pault@gcc.gnu.org>
    
    gcc/fortran
            PR fortran/93833
            * trans-array.c (get_array_ctor_var_strlen): If the character
            length backend_decl cannot be found, convert the expression and
            use the string length. Clear up some minor white space issues
            in the rest of the file.
    
    gcc/testsuite/
            PR fortran/93833
            * gfortran.dg/deferred_character_36.f90 : New test.
    
    (cherry picked from commit feae0af82753e06fbff6103da5fbb3b28e1ddbd7)

Diff:
---
 gcc/fortran/trans-array.c                           | 14 ++++++++++++++
 gcc/testsuite/gfortran.dg/deferred_character_36.f90 | 16 ++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 2afa05dda12..723e8360f59 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -2268,6 +2268,7 @@ get_array_ctor_var_strlen (stmtblock_t *block, gfc_expr * expr, tree * len)
   gfc_ref *ref;
   gfc_typespec *ts;
   mpz_t char_len;
+  gfc_se se;
 
   /* Don't bother if we already know the length is a constant.  */
   if (*len && INTEGER_CST_P (*len))
@@ -2313,6 +2314,19 @@ get_array_ctor_var_strlen (stmtblock_t *block, gfc_expr * expr, tree * len)
 	}
     }
 
+  /* A last ditch attempt that is sometimes needed for deferred characters.  */
+  if (!ts->u.cl->backend_decl)
+    {
+      gfc_init_se (&se, NULL);
+      if (expr->rank)
+	gfc_conv_expr_descriptor (&se, expr);
+      else
+	gfc_conv_expr (&se, expr);
+      gcc_assert (se.string_length != NULL_TREE);
+      gfc_add_block_to_block (block, &se.pre);
+      ts->u.cl->backend_decl = se.string_length;
+    }
+
   *len = ts->u.cl->backend_decl;
 }
 
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_36.f90 b/gcc/testsuite/gfortran.dg/deferred_character_36.f90
new file mode 100644
index 00000000000..65f2464e54e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/deferred_character_36.f90
@@ -0,0 +1,16 @@
+! { dg-do run }
+!
+! Test the fix for PR93833, which ICEd as shown.
+!
+! Contributed by Gerhard Steinmetz  <gscfq@t-online.de>
+!
+program p
+   character(:), allocatable :: c
+   c = "wxyz"
+contains
+   subroutine s
+      associate (y => [c])
+         if (any(y /= [c])) stop 1
+      end associate
+   end
+end


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-25  8:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25  8:56 [gcc r9-9201] Fortran: Fix deferred character lengths in array constructors [PR93833] Paul Thomas

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).