]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: error recovery after invalid use of CLASS variable [PR103475]
authorHarald Anlauf <anlauf@gmx.de>
Mon, 13 Feb 2023 21:02:44 +0000 (22:02 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 13 Feb 2023 21:06:10 +0000 (22:06 +0100)
gcc/fortran/ChangeLog:

PR fortran/103475
* primary.cc (gfc_expr_attr): Avoid NULL pointer dereference for
invalid use of CLASS variable.

gcc/testsuite/ChangeLog:

PR fortran/103475
* gfortran.dg/pr103475.f90: New test.

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

index 28ce5fea8656b8af4153381bb72e7abf29d5fc8e..1bea17d44fe603086382d3ce75a8843bb346b99e 100644 (file)
@@ -2770,7 +2770,7 @@ gfc_expr_attr (gfc_expr *e)
        {
          gfc_symbol *sym = e->value.function.esym->result;
          attr = sym->attr;
-         if (sym->ts.type == BT_CLASS)
+         if (sym->ts.type == BT_CLASS && sym->attr.class_ok)
            {
              attr.dimension = CLASS_DATA (sym)->attr.dimension;
              attr.pointer = CLASS_DATA (sym)->attr.class_pointer;
diff --git a/gcc/testsuite/gfortran.dg/pr103475.f90 b/gcc/testsuite/gfortran.dg/pr103475.f90
new file mode 100644 (file)
index 0000000..6cce5e8
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-O2 -Wall" }
+! PR fortran/103475 - ICE in gfc_expr_attr
+! Contributed by G.Steinmetz
+
+program p
+  type t
+  end type
+  class(t) :: x ! { dg-error "must be dummy, allocatable or pointer" }
+  y = x()       ! { dg-error "Cannot convert invalid class" }
+end