Fortran: Allow pointer deferred length associate selectors. [PR93794]
authorPaul Thomas <pault@gcc.gnu.org>
Fri, 8 Jan 2021 10:15:22 +0000 (10:15 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Fri, 8 Jan 2021 10:15:22 +0000 (10:15 +0000)
2021-01-05  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/93794
* trans-expr.c (gfc_conv_component_ref): Remove the condition
that deferred character length components only be allocatable.

gcc/testsuite/
PR fortran/93794
* gfortran.dg/deferred_character_35.f90 : New test.

gcc/fortran/trans-expr.c
gcc/testsuite/gfortran.dg/deferred_character_35.f90 [new file with mode: 0644]

index 1002448a5ff824b7458c6d1d6b502acfc6800cc9..7150e48bc9397b1ba921ec7257951fdf9d14e7ff 100644 (file)
@@ -2670,7 +2670,7 @@ gfc_conv_component_ref (gfc_se * se, gfc_ref * ref)
   /* Allocatable deferred char arrays are to be handled by the gfc_deferred_
      strlen () conditional below.  */
   if (c->ts.type == BT_CHARACTER && !c->attr.proc_pointer
-      && !(c->attr.allocatable && c->ts.deferred)
+      && !c->ts.deferred
       && !c->attr.pdt_string)
     {
       tmp = c->ts.u.cl->backend_decl;
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_35.f90 b/gcc/testsuite/gfortran.dg/deferred_character_35.f90
new file mode 100644 (file)
index 0000000..c28f52f
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do compile }
+!
+! Test the fix for PR93794, where the ASSOCIATE statement ICED on the
+! deferred character length, pointer component.
+!
+! Contributed by Gerhard Steinmetz  <gscfq@t-online.de>
+!
+program p
+   type t
+      character(:), pointer :: a
+   end type
+   type(t) :: z
+   character(4), target :: c = 'abcd'
+   z%a => c
+   associate (y => z%a)
+      print *, y
+   end associate
+end