]> gcc.gnu.org Git - 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 18:29:12 +0000 (20:29 +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 f946145eb1b5ee65367789735716880805841aa2..3c5246c7302f5cb7c274a8d5544ad58b4d27ea27 100644 (file)
@@ -3809,6 +3809,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 e1e4c1caeb40d903caf3389dd8834de44be6d3ae..ef6c86af2f957323d1ae696c891f4feea8e142f8 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 3e19d5fdfbebf139e9c43cc97fd7f4e8b598f523..1501abfffd2688475555387578e08b352872c7d7 100644 (file)
@@ -4440,6 +4440,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
This page took 0.085952 seconds and 5 git commands to generate.