public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-5636] Fortran: error recovery on invalid array section [PR108609]
Date: Wed,  1 Feb 2023 20:13:15 +0000 (GMT)	[thread overview]
Message-ID: <20230201201315.F3B9B3858D33@sourceware.org> (raw)

https://gcc.gnu.org/g:88a2a09dd4529107e7ef7a6e7ce43acf96457173

commit r13-5636-g88a2a09dd4529107e7ef7a6e7ce43acf96457173
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Feb 1 21:01:32 2023 +0100

    Fortran: error recovery on invalid array section [PR108609]
    
    The testcase for PR108527 uncovered a latent issue with invalid array
    sections that resulted in different paths being taken on different
    architectures.  Detect the invalid array declaration for a clean recovery.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108609
            * expr.cc (find_array_section): Add check to prevent interpreting an
            mpz non-integer constant as an integer.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/108609
            * gfortran.dg/pr108527.f90: Adjust test pattern.

Diff:
---
 gcc/fortran/expr.cc                    | 6 +++++-
 gcc/testsuite/gfortran.dg/pr108527.f90 | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 3036b1be60f..c295721b9d6 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -1552,7 +1552,11 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
       lower = ref->u.ar.as->lower[d];
       upper = ref->u.ar.as->upper[d];
 
-      if (!lower || !upper)
+      if (!lower || !upper
+	  || lower->expr_type != EXPR_CONSTANT
+	  || upper->expr_type != EXPR_CONSTANT
+	  || lower->ts.type != BT_INTEGER
+	  || upper->ts.type != BT_INTEGER)
 	{
 	  t = false;
 	  goto cleanup;
diff --git a/gcc/testsuite/gfortran.dg/pr108527.f90 b/gcc/testsuite/gfortran.dg/pr108527.f90
index c97ba3111cb..804514810ac 100644
--- a/gcc/testsuite/gfortran.dg/pr108527.f90
+++ b/gcc/testsuite/gfortran.dg/pr108527.f90
@@ -4,7 +4,7 @@
 
 program p
   integer, parameter :: a((2.)) = [4,8] ! { dg-error "must be of INTEGER type" }
-  integer(a(1:1)) :: b                  ! { dg-error "out of bounds" }
+  integer(a(1:1)) :: b                  ! { dg-error "Unclassifiable statement" }
 end
 
 ! { dg-prune-output "Parameter array" }

                 reply	other threads:[~2023-02-01 20:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230201201315.F3B9B3858D33@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).