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 r12-9179] Fortran: error recovery on invalid assumed size reference [PR104554]
Date: Thu, 16 Feb 2023 17:30:40 +0000 (GMT)	[thread overview]
Message-ID: <20230216173040.89B3C3858D33@sourceware.org> (raw)

https://gcc.gnu.org/g:e2c6bc6bb5628bb51b56d1da3f9907ae45a3a01b

commit r12-9179-ge2c6bc6bb5628bb51b56d1da3f9907ae45a3a01b
Author: Steve Kargl <kargl@gcc.gnu.org>
Date:   Wed Feb 15 22:20:22 2023 +0100

    Fortran: error recovery on invalid assumed size reference [PR104554]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104554
            * resolve.cc (check_assumed_size_reference): Avoid NULL pointer
            dereference.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104554
            * gfortran.dg/pr104554.f90: New test.
    
    (cherry picked from commit a418129273725fd02e881e6fb5e0877287a1356c)

Diff:
---
 gcc/fortran/resolve.cc                 |  8 +++++---
 gcc/testsuite/gfortran.dg/pr104554.f90 | 11 +++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 565b212c4c8..532ca05b69c 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -1670,9 +1670,11 @@ check_assumed_size_reference (gfc_symbol *sym, gfc_expr *e)
 
   /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
      What should it be?  */
-  if (e->ref && (e->ref->u.ar.end[e->ref->u.ar.as->rank - 1] == NULL)
-	  && (e->ref->u.ar.as->type == AS_ASSUMED_SIZE)
-	       && (e->ref->u.ar.type == AR_FULL))
+  if (e->ref
+      && e->ref->u.ar.as
+      && (e->ref->u.ar.end[e->ref->u.ar.as->rank - 1] == NULL)
+      && (e->ref->u.ar.as->type == AS_ASSUMED_SIZE)
+      && (e->ref->u.ar.type == AR_FULL))
     {
       gfc_error ("The upper bound in the last dimension must "
 		 "appear in the reference to the assumed size "
diff --git a/gcc/testsuite/gfortran.dg/pr104554.f90 b/gcc/testsuite/gfortran.dg/pr104554.f90
new file mode 100644
index 00000000000..099f219c85d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104554.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/104554 - ICE in check_assumed_size_reference
+! Contributed by G.Steinmetz
+
+program p
+  type t
+     integer :: a
+  end type
+  class(t) :: x(*) ! { dg-error "Assumed size array" }
+  x%a = 3
+end

                 reply	other threads:[~2023-02-16 17:30 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=20230216173040.89B3C3858D33@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).