Hi all,

during debugging I found a segfault of gfortran, when it encounters an illegal
fortran code. The mistake in Fortran is flagged correctly, but later gfortran
crashes. This patch prevents the crash.

Bootstraps and regtest ok on x86_64-linux-gnu.

Ok for trunk?

Regards,
        Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

Attachment: crashfix1_v1.clog
Description: Binary data

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 942a9ad..465cf2b 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -2639,6 +2639,10 @@ found:
     expr->ts = sym->ts;
   expr->value.function.name = sym->name;
   expr->value.function.esym = sym;
+  /* Prevent crash when sym->ts.u.derived->components is not set due to previous
+     error(s).  */
+  if (sym->ts.type == BT_CLASS && !CLASS_DATA (sym))
+    return MATCH_ERROR;
   if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->as)
     expr->rank = CLASS_DATA (sym)->as->rank;
   else if (sym->as != NULL)
diff --git a/gcc/testsuite/gfortran.dg/pointer_2.f90 b/gcc/testsuite/gfortran.dg/pointer_2.f90
new file mode 100644
index 0000000..d3b95d6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pointer_2.f90
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! Check that the compiler reports the errors, but does not segfault.
+! Contributed by: Andre Vehreschild  <ve...@gcc.gnu.org>
+!
+program test
+    implicit none
+    class(*), pointer :: P
+    class(*), allocatable :: P2
+
+    allocate(P2, source=convertType(P))
+
+contains
+
+  function convertType(in) ! { dg-error "must be dummy, allocatable or pointer" }
+    class(*), intent(in) :: in
+    class(*) :: convertType
+  end function
+end program test

Reply via email to