]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Modify checks to avoid referencing NULL pointer.
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 27 Mar 2023 01:44:35 +0000 (18:44 -0700)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 27 Mar 2023 01:56:20 +0000 (18:56 -0700)
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.

gcc/fortran/decl.cc
gcc/fortran/parse.cc
gcc/testsuite/gfortran.dg/class_result_4.f90
gcc/testsuite/gfortran.dg/pr85779_3.f90

index b89ed17be50413da9783cd7faf0687431afb5672..76f1694569c716fd42a327dec5c9a31b5a531c79 100644 (file)
@@ -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.  */
index 530f2075745a8640ebdc6a3cac26185df36252ce..3e9c6514c8008ea8564fee91ab004bd7e85811a0 100644 (file)
@@ -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);
index 4b22a3c30ee59c3339345e5409766215f25b7d92..5497ac652ecd911a249c94b7afe5cc1387fbabe8 100644 (file)
@@ -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
 
index fba1133b3ea78bc9b1dda586cdae9d92a0b27a1d..a81a9faf88e7bc43d86badb91f56c2e733cc521e 100644 (file)
@@ -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