diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 30107c977af8..a7071968dd34 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,7 @@ +2015-03-16 Andre Vehreschild + + * resolve.c: Prevent segfault on illegal input. + 2015-03-14 Mikael Morin PR fortran/61138 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 942a9ad9ac4d..465cf2ba8cf1 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/ChangeLog b/gcc/testsuite/ChangeLog index edfdf6bd28f1..55d00b076d80 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-03-16 Andre Vehreschild + + * gfortran.dg/pointer_2.f90: New test. + 2015-03-16 Eric Botcazou * testsuite/g++.dg/pr65049.C: New test. diff --git a/gcc/testsuite/gfortran.dg/pointer_2.f90 b/gcc/testsuite/gfortran.dg/pointer_2.f90 new file mode 100644 index 000000000000..a9b039d350b5 --- /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 +! +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