PR fortran/95340 - ICE in gfc_match_select_rank, at fortran/match.c:6690
authorHarald Anlauf <anlauf@gmx.de>
Sun, 28 Jun 2020 14:24:15 +0000 (16:24 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Sun, 28 Jun 2020 14:24:15 +0000 (16:24 +0200)
Do not dereference NULL pointer when querying array shape of possibly
improperly delared variable.

gcc/fortran/
PR fortran/95340
* match.c (gfc_match_select_rank): Do not dereference NULL pointer.

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

index b011634792e5c6b00d5bce5f29835c8b4ac19f7d..db5174f3f211cd8624f02ae83fe154df132d2b24 100644 (file)
@@ -6695,7 +6695,8 @@ gfc_match_select_rank (void)
       if (expr1->symtree)
        {
          sym = expr1->symtree->n.sym;
-         as = sym->ts.type == BT_CLASS ? CLASS_DATA (sym)->as : sym->as;
+         as = (sym->ts.type == BT_CLASS
+               && CLASS_DATA (sym)) ? CLASS_DATA (sym)->as : sym->as;
        }
 
       if (expr1->expr_type != EXPR_VARIABLE
diff --git a/gcc/testsuite/gfortran.dg/pr95340.f90 b/gcc/testsuite/gfortran.dg/pr95340.f90
new file mode 100644 (file)
index 0000000..edcdc93
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR fortran/95340 - ICE in gfc_match_select_rank, at fortran/match.c:6690
+
+program p
+  type t
+  end type t
+  class(t) :: z   ! { dg-error "must be dummy, allocatable or pointer" }
+  select rank (z) ! { dg-error "must be an assumed rank variable" }
+  end select      ! { dg-error "Expecting END PROGRAM" }
+end