This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, Fortran] PR 40246 - nullify pointer to fix ice-on-invalid-code
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Tue, 26 May 2009 20:37:32 +0200
- Subject: [Patch, Fortran] PR 40246 - nullify pointer to fix ice-on-invalid-code
Dear all,
the following patch fixes an ICE in NULLIFY, which only
occurs if there are more than one arguments of which
one is invalid. The problem is that new_st->next is
freed but new_st.next still points to the old memory
address.
For the test case I have, it does not matter, but I
think one also needs to free new_st->expr1 and ->expr2,
even though valgrind shows no difference for the
attached example.
The other question is whether one needs a test case or
not. I included one ...
Build on x86-64-linux and currently regtesting.
OK for the trunk (assuming successful regtesting)?
Tobias
2009-05-26 Tobias Burnus <burnus@net-b.de>
PR fortran/40246
* match.c (gfc_match_nullify): NULLify freed pointer.
2009-05-26 Tobias Burnus <burnus@net-b.de>
PR fortran/40246
* gfortran.dg/nullify_4.f90: New test.
Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c (Revision 147859)
+++ gcc/fortran/match.c (Arbeitskopie)
@@ -2418,6 +2418,11 @@ syntax:
cleanup:
gfc_free_statements (new_st.next);
+ new_st.next = NULL;
+ gfc_free_expr (new_st.expr1);
+ new_st.expr1 = NULL;
+ gfc_free_expr (new_st.expr2);
+ new_st.expr2 = NULL;
return MATCH_ERROR;
}
Index: gcc/testsuite/gfortran.dg/nullify_4.f90
===================================================================
--- gcc/testsuite/gfortran.dg/nullify_4.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/nullify_4.f90 (Revision 0)
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/40246
+!
+! Check error recovery; was crashing before.
+!
+real, pointer :: ptr
+nullify(ptr, mesh%coarser) ! { dg-error "Syntax error in NULLIFY statement" }
+end