summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2022-03-09 21:58:26 +0100
committerHarald Anlauf <anlauf@gmx.de>2022-05-16 21:53:50 +0200
commit6b8cd1fb402163e16d2a139f4bee346ff0c8f234 (patch)
tree97c3b574ac70b220550e3f60078a5242ea57f6f9
parentf43db17894744827d93ddcea7952d4ecf1f83f30 (diff)
Fortran: improve error recovery on invalid array section
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)
-rw-r--r--gcc/fortran/expr.c4
-rw-r--r--gcc/testsuite/gfortran.dg/pr104849.f909
2 files changed, 12 insertions, 1 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 7b61488bfe9..4276fe62c61 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1552,7 +1552,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
index 00000000000..ae221b5ba10
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104849.f90
@@ -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