The following obvious patch fixes a NULL pointer dereference:

Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c  (revision 256671)
+++ gcc/fortran/expr.c  (working copy)
@@ -4267,7 +4269,7 @@
         gfc_set_constant_character_len (len, init, -1);
       else if (init
               && init->ts.type == BT_CHARACTER
-               && init->ts.u.cl
+               && init->ts.u.cl && init->ts.u.cl->length
                && mpz_cmp (ts->u.cl->length->value.integer,
                            init->ts.u.cl->length->value.integer))
         {

Regtests without new failures on i686-pc-linux-gnu.
Testcase derived from PR, see below.

Changelog:

2018-01-17  Harald Anlauf  <anl...@gmx.de>

        PR fortran/83864
        * expr.c (add_init_expr_to_sym): Do not dereference NULL pointer.


Testcase:

2018-01-17  Harald Anlauf  <anl...@gmx.de>

        PR fortran/83864
        * gfortran.dg/pr83864.f90: New test.


Index: gfortran.dg/pr83864.f90
===================================================================
--- gfortran.dg/pr83864.f90     (revision 0)
+++ gfortran.dg/pr83864.f90     (revision 0)
@@ -0,0 +1,13 @@
+! { dg-do run }
+! PR fortran/83864
+!
+! Derived from PR by Contributed by Gerhard Steinmetz <gs...@t-online.de>
+!
+program p
+  implicit none
+  type t
+     character :: c(3) = transfer('abc','z',3)
+  end type t
+  type(t) :: x
+  if (any (x%c /= ["a", "b", "c"])) call abort ()
+end

Whoever wants to commit this to 8-trunk, please do so.

Thanks,
Harald

Reply via email to