From 6c25f7962556e2217d5070720ac879c40063209a Mon Sep 17 00:00:00 2001 From: Andre Vehreschild Date: Mon, 16 Mar 2015 11:29:59 +0100 Subject: [PATCH] resolve.c: Prevent segfault on illegal input. gcc/fortran/ChangeLog: 2015-03-16 Andre Vehreschild * resolve.c: Prevent segfault on illegal input. gcc/testsuite/ChangeLog: 2015-03-16 Andre Vehreschild * gfortran.dg/pointer_2.f90: New test. From-SVN: r221455 --- gcc/fortran/ChangeLog | 4 ++++ gcc/fortran/resolve.c | 4 ++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gfortran.dg/pointer_2.f90 | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pointer_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 30107c977af..a7071968dd3 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 942a9ad9ac4..465cf2ba8cf 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 edfdf6bd28f..55d00b076d8 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 00000000000..a9b039d350b --- /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 -- 2.30.2