]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran - ICE in gfc_check_do_variable, at fortran/parse.c:4446
authorHarald Anlauf <anlauf@gmx.de>
Wed, 16 Jun 2021 20:04:22 +0000 (22:04 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 18 Jun 2021 17:56:16 +0000 (19:56 +0200)
Avoid NULL pointer dereferences during error recovery.

gcc/fortran/ChangeLog:

PR fortran/95501
PR fortran/95502
* expr.c (gfc_check_pointer_assign): Avoid NULL pointer
dereference.
* match.c (gfc_match_pointer_assignment): Likewise.
* parse.c (gfc_check_do_variable): Avoid comparison with NULL
symtree.

gcc/testsuite/ChangeLog:

PR fortran/95501
PR fortran/95502
* gfortran.dg/pr95502.f90: New test.

(cherry picked from commit cfe0a2ec26867b290eb84af00317e60f8b67455c)

gcc/fortran/expr.c
gcc/fortran/match.c
gcc/fortran/parse.c
gcc/testsuite/gfortran.dg/pr95502.f90 [new file with mode: 0644]

index 956003ec605e46545cb73876a148d4835b72bc06..b11ae7ce5c5ca1818b381e6b7e5c20c21936141d 100644 (file)
@@ -3815,6 +3815,9 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue,
   int proc_pointer;
   bool same_rank;
 
+  if (!lvalue->symtree)
+    return false;
+
   lhs_attr = gfc_expr_attr (lvalue);
   if (lvalue->ts.type == BT_UNKNOWN && !lhs_attr.proc_pointer)
     {
index 393755e4d932ecf9e49705f32bb487351db3f90f..b312a26a718dc2d587c6c8bd7f10633b0f45d30a 100644 (file)
@@ -1409,7 +1409,7 @@ gfc_match_pointer_assignment (void)
   gfc_matching_procptr_assignment = 0;
 
   m = gfc_match (" %v =>", &lvalue);
-  if (m != MATCH_YES)
+  if (m != MATCH_YES || !lvalue->symtree)
     {
       m = MATCH_NO;
       goto cleanup;
index 1549f8e16359775e6bbc1e6a1ff8abe747369964..610e729c68a2b7ef7a884bf9a1fbd648e9cfd268 100644 (file)
@@ -4485,6 +4485,9 @@ gfc_check_do_variable (gfc_symtree *st)
 {
   gfc_state_data *s;
 
+  if (!st)
+    return 0;
+
   for (s=gfc_state_stack; s; s = s->previous)
     if (s->do_variable == st)
       {
diff --git a/gcc/testsuite/gfortran.dg/pr95502.f90 b/gcc/testsuite/gfortran.dg/pr95502.f90
new file mode 100644 (file)
index 0000000..d40fd9a
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/95502 - ICE in gfc_check_do_variable, at fortran/parse.c:4446
+
+program p
+  integer, pointer :: z
+  nullify (z%kind)  ! { dg-error "in variable definition context" }
+  z%kind => NULL()  ! { dg-error "constant expression" }
+end