The attached patch fixes an ICE-on-valid that probably goes back to
rev.128130.  Apparently the patch applied back then did not check
this code path which resulted in a NULL pointer dereference.  This
is remedied by the new testcase base on comment #0 in this PR.

The PR mentions another wrong-code issue to be addressed separately.

OK for trunk?  And shall this fix be backported?

Thanks,
Harald

2019-02-03  Harald Anlauf  <anl...@gmx.de>

        PR fortran/89077
        * decl.c (add_init_expr_to_sym): Copy length of string initializer
        to declared symbol.

2019-02-03  Harald Anlauf  <anl...@gmx.de>

        PR fortran/89077
        * gfortran.dg/pr89077.f90: New test.

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c  (revision 268502)
+++ gcc/fortran/decl.c  (working copy)
@@ -1921,7 +1921,7 @@
                    }
                  else if (init->ts.u.cl && init->ts.u.cl->length)
                    sym->ts.u.cl->length =
-                               gfc_copy_expr (sym->value->ts.u.cl->length);
+                               gfc_copy_expr (init->ts.u.cl->length);
                }
            }
          /* Update initializer character length according symbol.  */
Index: gcc/testsuite/gfortran.dg/pr89077.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr89077.f90       (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr89077.f90       (working copy)
@@ -0,0 +1,11 @@
+! { dg-do run }
+!
+! PR fortran/89077 - ICE using * as len specifier for character parameter
+
+program test
+  implicit none
+  integer :: i
+  character(*), parameter :: s = 'abcdef'
+  character(*), parameter :: t = transfer ([(s(i:i), i=1,len(s))], s)
+  if (len (t) /= len (s) .or. t /= s) stop 1
+end

Reply via email to