]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: improve error recovery on invalid array section
authorHarald Anlauf <anlauf@gmx.de>
Wed, 9 Mar 2022 20:58:26 +0000 (21:58 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 16 May 2022 19:26:49 +0000 (21:26 +0200)
gcc/fortran/ChangeLog:

PR fortran/104849
* expr.c (find_array_section): Avoid NULL pointer dereference on
invalid array section.

gcc/testsuite/ChangeLog:

PR fortran/104849
* gfortran.dg/pr104849.f90: New test.

(cherry picked from commit 22015e77d3e45306077396b9de8a8a28bb67fb20)

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

index d19c6c9980bab5a7f09c041ebed37ac1952d14ee..3570ff00d1c84d57275302ee729b21f8d7cb2cab 100644 (file)
@@ -1591,7 +1591,9 @@ 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))
+             || (step && step->expr_type != EXPR_CONSTANT)
+             || (!begin && !lower)
+             || (!finish && !upper))
            {
              t = false;
              goto cleanup;
diff --git a/gcc/testsuite/gfortran.dg/pr104849.f90 b/gcc/testsuite/gfortran.dg/pr104849.f90
new file mode 100644 (file)
index 0000000..ae221b5
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/104849 - ICE in find_array_section
+! Contributed by G.Steinmetz
+
+program p
+  integer, parameter :: a(:) = [1, 2] ! { dg-error "deferred shape" }
+  integer :: x(2)
+  data x /a(:)/                       ! { dg-error "Invalid" }
+end