diff options
author | Harald Anlauf <anlauf@gmx.de> | 2022-05-10 23:41:57 +0200 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2022-05-16 21:53:54 +0200 |
commit | a9717558aaaa340352c832413343cef71f588eaf (patch) | |
tree | c63d0689c0c573335d64c73727786f5395ce73bf | |
parent | 6b8cd1fb402163e16d2a139f4bee346ff0c8f234 (diff) |
Fortran: fix error recovery on invalid array section
gcc/fortran/ChangeLog:
PR fortran/105230
* expr.c (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>
(cherry picked from commit 0acdbe29f66017fc5cca40dcbd72a0dd41491d07)
-rw-r--r-- | gcc/fortran/expr.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/pr105230.f90 | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 4276fe62c61..35bd0bd6d3b 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1553,8 +1553,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 index 00000000000..6c6b42ef9bf --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr105230.f90 @@ -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 |