public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-10007] Fortran: fix error recovery on invalid array section
@ 2022-05-16 19:11 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-05-16 19:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:34c60e5e776d29ae6eb9e2e94af1c67666ec1caa

commit r11-10007-g34c60e5e776d29ae6eb9e2e94af1c67666ec1caa
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue May 10 23:41:57 2022 +0200

    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)

Diff:
---
 gcc/fortran/expr.c                     | 4 ++--
 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 68116da5d42..6f27b4bf440 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1592,8 +1592,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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-16 19:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 19:11 [gcc r11-10007] Fortran: fix error recovery on invalid array section Harald Anlauf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).