public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jerry DeLisle <jvdelisle@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-9320] Fortran: Modify checks to avoid referencing NULL pointer.
Date: Mon, 27 Mar 2023 02:00:17 +0000 (GMT)	[thread overview]
Message-ID: <20230327020017.0BE793858D37@sourceware.org> (raw)

https://gcc.gnu.org/g:82ec75a726b3f8f874dacb0cb342c9bbd1233cc0

commit r12-9320-g82ec75a726b3f8f874dacb0cb342c9bbd1233cc0
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Sun Mar 26 18:44:35 2023 -0700

    Fortran: Modify checks to avoid referencing NULL pointer.
    
    Backport from mainline.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/102331
            * decl.cc (attr_decl1): Guard against NULL pointer.
            * parse.cc (match_deferred_characteristics): Include BT_CLASS in check
            for derived being undefined.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/102331
            * gfortran.dg/class_result_4.f90: Update error message check.
            * gfortran.dg/pr85779_3.f90: Update error message check.

Diff:
---
 gcc/fortran/decl.cc                          | 4 +++-
 gcc/fortran/parse.cc                         | 4 ++--
 gcc/testsuite/gfortran.dg/class_result_4.f90 | 2 +-
 gcc/testsuite/gfortran.dg/pr85779_3.f90      | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index b89ed17be50..76f1694569c 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -8730,7 +8730,9 @@ attr_decl1 (void)
   /* Update symbol table.  DIMENSION attribute is set in
      gfc_set_array_spec().  For CLASS variables, this must be applied
      to the first component, or '_data' field.  */
-  if (sym->ts.type == BT_CLASS && sym->ts.u.derived->attr.is_class)
+  if (sym->ts.type == BT_CLASS
+      && sym->ts.u.derived
+      && sym->ts.u.derived->attr.is_class)
     {
       /* gfc_set_array_spec sets sym->attr not CLASS_DATA(sym)->attr.  Check
 	 for duplicate attribute here.  */
diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index 530f2075745..3e9c6514c80 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -3911,7 +3911,7 @@ match_deferred_characteristics (gfc_typespec * ts)
   m = gfc_match_prefix (ts);
   gfc_buffer_error (false);
 
-  if (ts->type == BT_DERIVED)
+  if (ts->type == BT_DERIVED || ts->type == BT_CLASS)
     {
       ts->kind = 0;
 
@@ -4195,7 +4195,7 @@ declSt:
   if (bad_characteristic)
     {
       ts = &gfc_current_block ()->result->ts;
-      if (ts->type != BT_DERIVED)
+      if (ts->type != BT_DERIVED && ts->type != BT_CLASS)
 	gfc_error ("Bad kind expression for function %qs at %L",
 		   gfc_current_block ()->name,
 		   &gfc_current_block ()->declared_at);
diff --git a/gcc/testsuite/gfortran.dg/class_result_4.f90 b/gcc/testsuite/gfortran.dg/class_result_4.f90
index 4b22a3c30ee..5497ac652ec 100644
--- a/gcc/testsuite/gfortran.dg/class_result_4.f90
+++ b/gcc/testsuite/gfortran.dg/class_result_4.f90
@@ -1,6 +1,6 @@
 ! { dg-do compile }
 ! PR fortran/78500
-class(t) function f() ! { dg-error "must be dummy, allocatable or pointer" }
+class(t) function f() ! { dg-error "is not accessible" }
    f = 1              ! { dg-error "variable must not be polymorphic" }
 end
 
diff --git a/gcc/testsuite/gfortran.dg/pr85779_3.f90 b/gcc/testsuite/gfortran.dg/pr85779_3.f90
index fba1133b3ea..a81a9faf88e 100644
--- a/gcc/testsuite/gfortran.dg/pr85779_3.f90
+++ b/gcc/testsuite/gfortran.dg/pr85779_3.f90
@@ -1,6 +1,6 @@
 ! { dg-do compile }
 ! PR fortran/85779
-class(t) function f()   ! { dg-error "must be dummy, allocatable or pointer" }
+class(t) function f()   ! { dg-error "is not accessible" }
    type f               ! { dg-error "already has a basic type" }
    end type             ! { dg-error "END FUNCTION statement" }
 end

                 reply	other threads:[~2023-03-27  2:00 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=20230327020017.0BE793858D37@sourceware.org \
    --to=jvdelisle@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).