From 902d624f45c2be8ca865017539f0c224c913f146 Mon Sep 17 00:00:00 2001 From: Louis Krupp Date: Thu, 15 Sep 2016 23:54:40 +0000 Subject: [PATCH] re PR fortran/69963 (ICE out of memory on displaced implicit character) 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-15 Louis Krupp PR fortran/69963 * gfortran.dg/misplaced_implicit_character.f90: New test. From-SVN: r240168 --- gcc/fortran/ChangeLog | 5 ++++ gcc/fortran/parse.c | 25 +++++++++++++++++++ gcc/testsuite/ChangeLog | 5 ++++ .../misplaced_implicit_character.f90 | 8 ++++++ 4 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90 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