Fortran: avoid NULL pointer dereference on invalid DATA constant [PR99349]
authorHarald Anlauf <anlauf@gmx.de>
Fri, 2 Sep 2022 19:07:26 +0000 (21:07 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 2 Sep 2022 19:10:44 +0000 (21:10 +0200)
gcc/fortran/ChangeLog:

PR fortran/99349
* decl.cc (match_data_constant): Avoid NULL pointer dereference.

gcc/testsuite/ChangeLog:

PR fortran/99349
* gfortran.dg/pr99349.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
gcc/fortran/decl.cc
gcc/testsuite/gfortran.dg/pr99349.f90 [new file with mode: 0644]

index b640051..0f9b2ce 100644 (file)
@@ -423,7 +423,8 @@ match_data_constant (gfc_expr **result)
         data-pointer-initialization compatible (7.5.4.6) with the initial
         data target; the data statement object is initially associated
         with the target.  */
-      if ((*result)->symtree->n.sym->attr.save
+      if ((*result)->symtree
+         && (*result)->symtree->n.sym->attr.save
          && (*result)->symtree->n.sym->attr.target)
        return m;
       gfc_free_expr (*result);
diff --git a/gcc/testsuite/gfortran.dg/pr99349.f90 b/gcc/testsuite/gfortran.dg/pr99349.f90
new file mode 100644 (file)
index 0000000..e1f4628
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/99349 - ICE in match_data_constant
+! Contributed by G.Steinmetz
+
+function f()
+  logical, parameter :: a((1.)/0) = .true. ! { dg-error "Parameter array" }
+  integer :: b
+  data b /a%kind/ ! { dg-error "Syntax error" }
+end