Hi Tobias, hi all, thanks for the review. Commited as r221455:
r221455 | vehre | 2015-03-16 11:29:59 +0100 (Mo, 16. Mär 2015) | 13 Zeilen gcc/fortran/ChangeLog: 2015-03-16 Andre Vehreschild <ve...@gmx.de> * resolve.c: Prevent segfault on illegal input. gcc/testsuite/ChangeLog: 2015-03-16 Andre Vehreschild <ve...@gmx.de> * gfortran.dg/pointer_2.f90: New test. Regards, Andre On Fri, 13 Mar 2015 14:05:00 +0100 Tobias Burnus <tobias.bur...@physik.fu-berlin.de> wrote: > Andre Vehreschild wrote: > > 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? > > OK. Thanks for the patch. > > Tobias -- Andre Vehreschild * Email: vehre ad gmx dot de
Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 221454) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,7 @@ +2015-03-16 Andre Vehreschild <ve...@gmx.de> + + * resolve.c: Prevent segfault on illegal input. + 2015-03-14 Mikael Morin <mik...@gcc.gnu.org> PR fortran/61138 Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (Revision 221454) +++ gcc/fortran/resolve.c (Arbeitskopie) @@ -2639,6 +2639,10 @@ 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) Index: gcc/testsuite/gfortran.dg/pointer_2.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pointer_2.f90 (Revision 0) +++ gcc/testsuite/gfortran.dg/pointer_2.f90 (Revision 221455) @@ -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 Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (Revision 221454) +++ gcc/testsuite/ChangeLog (Arbeitskopie) @@ -1,3 +1,7 @@ +2015-03-16 Andre Vehreschild <ve...@gmx.de> + + * gfortran.dg/pointer_2.f90: New test. + 2015-03-16 Eric Botcazou <ebotca...@adacore.com> * testsuite/g++.dg/pr65049.C: New test.