From 5270c302f0ef520b9f6f96a1c94caa5962754401 Mon Sep 17 00:00:00 2001 From: Asher Langton Date: Thu, 22 Jun 2006 18:30:18 +0000 Subject: [PATCH] re PR fortran/24748 (substring of implicitly typed variable not rejected) PR fortran/24748 * primary.c (gfc_match_rvalue): Don't call match_substring for implicit non-character types. PR fortran/24748 * gfortran.dg/implicit_8.f90: New. From-SVN: r114901 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/primary.c | 16 +++++++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/implicit_8.f90 | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/implicit_8.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 55e66cdfdc8..a02bebdede7 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2006-06-22 Asher Langton + + PR fortran/24748 + * primary.c (gfc_match_rvalue): Don't call match_substring for + implicit non-character types. + 2006-06-22 Francois-Xavier Coudert PR libfortran/26769 diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 8fe129457b4..ad569fcf6b6 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -1912,6 +1912,8 @@ gfc_match_rvalue (gfc_expr ** result) gfc_expr *e; match m, m2; int i; + gfc_typespec *ts; + bool implicit_char; m = gfc_match_name (name); if (m != MATCH_YES) @@ -2156,10 +2158,22 @@ gfc_match_rvalue (gfc_expr ** result) if (m2 != MATCH_YES) { + /* Try to figure out whether we're dealing with a character type. + We're peeking ahead here, because we don't want to call + match_substring if we're dealing with an implicitly typed + non-character variable. */ + implicit_char = false; + if (sym->ts.type == BT_UNKNOWN) + { + ts = gfc_get_default_type (sym,NULL); + if (ts->type == BT_CHARACTER) + implicit_char = true; + } + /* See if this could possibly be a substring reference of a name that we're not sure is a variable yet. */ - if ((sym->ts.type == BT_UNKNOWN || sym->ts.type == BT_CHARACTER) + if ((implicit_char || sym->ts.type == BT_CHARACTER) && match_substring (sym->ts.cl, 0, &e->ref) == MATCH_YES) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e7d6f9d942a..87319529d33 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-06-22 Asher Langton + + PR fortran/24748 + * gfortran.dg/implicit_8.f90: New. + 2006-06-22 Zdenek Dvorak PR rtl-optimization/28121 diff --git a/gcc/testsuite/gfortran.dg/implicit_8.f90 b/gcc/testsuite/gfortran.dg/implicit_8.f90 new file mode 100644 index 00000000000..bdd11e615b9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/implicit_8.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! PR 24748 + +! The compiler used to crash trying to take a substring of an implicit +! real scalar. +subroutine variant1 + ybtable=ylocal(1:2) ! { dg-error "Syntax error in argument list" } +end + +! We want the behavior to be the same whether ylocal is implicitly +! or explicitly typed. +subroutine variant2 + real ylocal + ybtable=ylocal(1:2) ! { dg-error "Syntax error in argument list" } +end + -- 2.30.2