From: Steven G. Kargl Date: Sat, 7 Nov 2015 20:04:43 +0000 (+0000) Subject: re PR fortran/68151 (ICE on using select case with function of wrong type) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=727cde644d6175dcc5e22d4e1214bf3bac621efc;p=gcc.git re PR fortran/68151 (ICE on using select case with function of wrong type) 2015-11-07 Steven G. Kargl PR fortran/68151 * match.c (match_case_selector): Check for invalid type. 2015-11-07 Steven G. Kargl PR fortran/68151 * gfortran.dg/pr68151.f90: New test. From-SVN: r229938 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index acbb1b75f06..15583d9848b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2015-11-07 Steven G. Kargl + + PR fortran/68151 + * match.c (match_case_selector): Check for invalid type. + 2015-11-06 David Malcolm * cpp.c (cb_cpp_error): Convert parameter from location_t to diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 7abb5dee4a9..2844262e0f2 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -5018,7 +5018,9 @@ gfc_free_case_list (gfc_case *p) } -/* Match a single case selector. */ +/* Match a single case selector. Combining the requirements of F08:C830 + and F08:C832 (R838) means that the case-value must have either CHARACTER, + INTEGER, or LOGICAL type. */ static match match_case_selector (gfc_case **cp) @@ -5036,6 +5038,14 @@ match_case_selector (gfc_case **cp) goto need_expr; if (m == MATCH_ERROR) goto cleanup; + + if (c->high->ts.type != BT_LOGICAL && c->high->ts.type != BT_INTEGER + && c->high->ts.type != BT_CHARACTER) + { + gfc_error ("Expression in CASE selector at %L cannot be %s", + &c->high->where, gfc_typename (&c->high->ts)); + goto cleanup; + } } else { @@ -5045,6 +5055,14 @@ match_case_selector (gfc_case **cp) if (m == MATCH_NO) goto need_expr; + if (c->low->ts.type != BT_LOGICAL && c->low->ts.type != BT_INTEGER + && c->low->ts.type != BT_CHARACTER) + { + gfc_error ("Expression in CASE selector at %L cannot be %s", + &c->low->where, gfc_typename (&c->low->ts)); + goto cleanup; + } + /* If we're not looking at a ':' now, make a range out of a single target. Else get the upper bound for the case range. */ if (gfc_match_char (':') != MATCH_YES) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 18871bfae3e..c9df4b08166 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-07 Steven G. Kargl + + PR fortran/68151 + * gfortran.dg/pr68151.f90: New test. + 2015-11-07 Richard Sandiford PR tree-optimization/68235 diff --git a/gcc/testsuite/gfortran.dg/pr68151.f90 b/gcc/testsuite/gfortran.dg/pr68151.f90 new file mode 100644 index 00000000000..830d9f4f437 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr68151.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! PR fortran/68151 +! Original code contribute by Gerhard Steinmetz +! +! +program p + integer :: k = 1 + select case (k) + case (:huge(1._4)) ! { dg-error "Expression in CASE" } + case (:huge(2._8)) ! { dg-error "Expression in CASE" } + case ((1.0,2.0)) ! { dg-error "Expression in CASE" } + end select +end