diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 55380a01f57..ffc859a4128 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2016-09-15 Louis Krupp + PR fortran/69963 + * parse.c (reject_statement): Clear charlen pointers in implicit + character typespecs before those charlen structures are freed. + 2016-09-14 Bernd Edlinger * simplify.c (gfc_simplify_repeat): Fix a misplaced closing ')'. diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index 86f2c427368..d78a2c07eec 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -2399,6 +2399,29 @@ accept_statement (gfc_statement st) } +/* Clear default character types with charlen pointers that are about + to become invalid. */ + +static void +clear_default_charlen (gfc_namespace *ns, const gfc_charlen *cl, + const gfc_charlen *end) +{ + gfc_typespec *ts; + + for (ts = &ns->default_type[0]; ts < &ns->default_type[GFC_LETTERS]; ts++) + if (ts->type == BT_CHARACTER) + { + const gfc_charlen *cl2; + for (cl2 = cl; cl2 != end; cl2 = cl2->next) + if (ts->u.cl == cl2) + { + ts->u.cl = NULL; + ts->type = BT_UNKNOWN; + break; + } + } +} + /* Undo anything tentative that has been built for the current statement. */ @@ -2406,6 +2429,8 @@ static void reject_statement (void) { /* Revert to the previous charlen chain. */ + clear_default_charlen (gfc_current_ns, + gfc_current_ns->cl_list, gfc_current_ns->old_cl_list); gfc_free_charlen (gfc_current_ns->cl_list, gfc_current_ns->old_cl_list); gfc_current_ns->cl_list = gfc_current_ns->old_cl_list; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fdd2acdcca7..3c2087528a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-15 Louis Krupp + + PR fortran/69963 + * gfortran.dg/misplaced_implicit_character.f90: New test. + 2016-09-15 Bin Cheng PR tree-optimization/77503 diff --git a/gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90 b/gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90 new file mode 100644 index 00000000000..8471d419eb0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! PR fortran/69963 +subroutine s + real x ! { dg-error "" } + implicit character (a) ! { dg-error "IMPLICIT statement at .1. cannot follow data declaration statement at .2." } + + a1 = 'z' ! { dg-error "Symbol .a1. at .1. has no IMPLICIT type" } +end subroutine s