Fortran: fix error recovery on invalid array section
authorHarald Anlauf <anlauf@gmx.de>
Tue, 10 May 2022 21:41:57 +0000 (23:41 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 11 May 2022 17:13:17 +0000 (19:13 +0200)
gcc/fortran/ChangeLog:

PR fortran/105230
* expr.cc (find_array_section): Correct logic to avoid NULL
pointer dereference on invalid array section.

gcc/testsuite/ChangeLog:

PR fortran/105230
* gfortran.dg/pr105230.f90: New test.

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

index 86d61fe..be94c18 100644 (file)
@@ -1595,8 +1595,8 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
          if ((begin && begin->expr_type != EXPR_CONSTANT)
              || (finish && finish->expr_type != EXPR_CONSTANT)
              || (step && step->expr_type != EXPR_CONSTANT)
-             || (!begin && !lower)
-             || (!finish && !upper))
+             || !lower
+             || !upper)
            {
              t = false;
              goto cleanup;
diff --git a/gcc/testsuite/gfortran.dg/pr105230.f90 b/gcc/testsuite/gfortran.dg/pr105230.f90
new file mode 100644 (file)
index 0000000..6c6b42e
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/105230 - ICE in find_array_section
+! Contributed by G.Steinmetz
+
+program p
+  integer, parameter :: a(:) = [1, 2] ! { dg-error "deferred shape" }
+  print *, reshape([3, 4], a(1:2))
+end