]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: error recovery for invalid CLASS component [PR108434]
authorHarald Anlauf <anlauf@gmx.de>
Wed, 18 Jan 2023 21:13:29 +0000 (22:13 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 23 Jan 2023 21:26:50 +0000 (22:26 +0100)
gcc/fortran/ChangeLog:

PR fortran/108434
* expr.cc (class_allocatable): Prevent NULL pointer dereference
or invalid read.
(class_pointer): Likewise.

gcc/testsuite/ChangeLog:

PR fortran/108434
* gfortran.dg/pr108434.f90: New test.

(cherry picked from commit 117848f425a3c0eda85517b4bdaf2ebe3bc705c2)

gcc/fortran/expr.cc
gcc/testsuite/gfortran.dg/pr108434.f90 [new file with mode: 0644]

index 69d0b57c688350a01cca156dcb2bb4caf2434c52..ab54d43bce236e625a29d620e078356a8e58a2c6 100644 (file)
@@ -4996,14 +4996,14 @@ get_union_initializer (gfc_symbol *union_type, gfc_component **map_p)
 static bool
 class_allocatable (gfc_component *comp)
 {
-  return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
+  return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp)
     && CLASS_DATA (comp)->attr.allocatable;
 }
 
 static bool
 class_pointer (gfc_component *comp)
 {
-  return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
+  return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp)
     && CLASS_DATA (comp)->attr.pointer;
 }
 
diff --git a/gcc/testsuite/gfortran.dg/pr108434.f90 b/gcc/testsuite/gfortran.dg/pr108434.f90
new file mode 100644 (file)
index 0000000..e1768a5
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/108434 - ICE in class_allocatable
+! Contributed by G.Steinmetz
+
+program p
+  type t
+     class(c), pointer :: a(2) ! { dg-error "must have a deferred shape" }
+  end type t
+  class(t), allocatable :: x
+  class(t), pointer     :: y
+end