re PR fortran/71203 (ICE in add_init_expr_to_sym, at fortran/decl.c:1512 and :1564)
authorHarald Anlauf <anlauf@gmx.de>
Wed, 6 Mar 2019 21:06:35 +0000 (21:06 +0000)
committerHarald Anlauf <anlauf@gcc.gnu.org>
Wed, 6 Mar 2019 21:06:35 +0000 (21:06 +0000)
2019-03-06  Harald Anlauf  <anlauf@gmx.de>

PR fortran/71203
* expr.c (simplify_const_ref): Avoid null pointer dereference.

PR fortran/71203
* gfortran.dg/substr_8.f90: New test.

From-SVN: r269444

gcc/fortran/ChangeLog
gcc/fortran/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/substr_8.f90 [new file with mode: 0644]

index 9f4234900b6880cc7fb3b6d9a3abd67381c52165..2b23b997c6d99d49726fc5db21177a75a87f6bc6 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-06  Harald Anlauf  <anlauf@gmx.de>
+
+       PR fortran/71203
+       * expr.c (simplify_const_ref): Avoid null pointer dereference.
+
 2019-03-03  Harald Anlauf  <anlauf@gmx.de>
            Steven G. Kargl  <kargl@gcc.gnu.org>
 
index c3d78d358cf694473942dc7ed02b870325a3fb86..51552a79cdee2f12b91b02ceed71dd186361573d 100644 (file)
@@ -1897,8 +1897,14 @@ simplify_const_ref (gfc_expr *p)
                        string_len = 0;
 
                      if (!p->ts.u.cl)
-                       p->ts.u.cl = gfc_new_charlen (p->symtree->n.sym->ns,
-                                                     NULL);
+                       {
+                         if (p->symtree)
+                           p->ts.u.cl = gfc_new_charlen (p->symtree->n.sym->ns,
+                                                         NULL);
+                         else
+                           p->ts.u.cl = gfc_new_charlen (gfc_current_ns,
+                                                         NULL);
+                       }
                      else
                        gfc_free_expr (p->ts.u.cl->length);
 
index 4175bc4b24676f93022d2aba572768c673199ed9..4908a34dce798958ad240a49c945701e60c231e0 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-06  Harald Anlauf  <anlauf@gmx.de>
+
+       PR fortran/71203
+       * gfortran.dg/substr_8.f90: New test.
+
 2019-03-06  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/87148
diff --git a/gcc/testsuite/gfortran.dg/substr_8.f90 b/gcc/testsuite/gfortran.dg/substr_8.f90
new file mode 100644 (file)
index 0000000..a3b7787
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do run }
+! PR fortran/71203 - used to ICE on zero-length arrays or substrings
+! Derived from original test cases by Gerhard Steinmetz
+
+program p
+  implicit none
+  character(3), parameter :: a(4) = ' '
+  character(*), parameter :: b(4) = 'abc'
+  character(*), parameter :: x(*) = a(2:2)(3:1)
+  character(*), parameter :: y(*) = a(2:1)(3:1)
+  character(*), parameter :: z(*) = b(2:1)(2:3)
+  if (size (x) /= 1 .or. len(x) /= 0) stop 1
+  if (size (y) /= 0 .or. len(y) /= 0) stop 2
+  if (size (z) /= 0 .or. len(z) /= 2) stop 3
+end