gcc/gcc41-pr27954.patch

85 lines
2.2 KiB
Diff

2006-10-27 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/27954
* decl.c (gfc_free_data_all): New function to free all data structures
after errors in DATA statements and declarations.
(top_var_list): Use new function.(top_val_list): Use new function.
(gfc_match_data_decl): Use new function.
PR libgfortran/27954
* gfortran.dg/error_recovery_2.f90: New test.
--- gcc/fortran/decl.c (revision 118083)
+++ gcc/fortran/decl.c (revision 118086)
@@ -128,6 +128,21 @@ gfc_free_data (gfc_data * p)
}
+/* Free all data in a namespace. */
+static void
+gfc_free_data_all (gfc_namespace * ns)
+{
+ gfc_data *d;
+
+ for (;ns->data;)
+ {
+ d = ns->data->next;
+ gfc_free (ns->data);
+ ns->data = d;
+ }
+}
+
+
static match var_element (gfc_data_variable *);
/* Match a list of variables terminated by an iterator and a right
@@ -262,6 +277,7 @@ top_var_list (gfc_data * d)
syntax:
gfc_syntax_error (ST_DATA);
+ gfc_free_data_all (gfc_current_ns);
return MATCH_ERROR;
}
@@ -374,6 +390,7 @@ top_val_list (gfc_data * data)
syntax:
gfc_syntax_error (ST_DATA);
+ gfc_free_data_all (gfc_current_ns);
return MATCH_ERROR;
}
@@ -2368,6 +2385,8 @@ ok:
gfc_error ("Syntax error in data declaration at %C");
m = MATCH_ERROR;
+ gfc_free_data_all (gfc_current_ns);
+
cleanup:
gfc_free_array_spec (current_as);
current_as = NULL;
--- gcc/testsuite/gfortran.dg/error_recovery_2.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/error_recovery_2.f90 (revision 118086)
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! PR27954 Internal compiler error on bad statements
+! Derived from test case submitted in PR.
+subroutine bad1
+ character*20 :: y, x 00 ! { dg-error "Syntax error" }
+ data y /'abcdef'/, x /'jbnhjk'/ pp ! { dg-error "Syntax error" }
+end subroutine bad1
+
+subroutine bad2
+ character*20 :: y, x 00 ! { dg-error "Syntax error" }
+ data y /'abcdef'/, x /'jbnhjk'/ pp ! { dg-error "Syntax error" }
+ print *, "basket case."
+end subroutine bad2
+
+subroutine bad3
+ implicit none
+ character*20 :: y, x 00 ! { dg-error "Syntax error" }
+ data y /'abcdef'/, x /'jbnhjk'/ pp ! { dg-error "Syntax error" }
+ print *, "basket case that segfaults without patch."
+end subroutine bad3
+