[PATCH, fortran] PR/83864 - ICE in gfc_apply_init, at fortran/expr.c:4271

Harald Anlauf anlauf@gmx.de
Wed Jan 17 22:25:00 GMT 2018


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  <anlauf@gmx.de>

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


Testcase:

2018-01-17  Harald Anlauf  <anlauf@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 <gscfq@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



More information about the Gcc-patches mailing list