* [PATCH] PR fortran/68151 -- Check CASE selector for valid type
@ 2015-11-01 21:16 Steve Kargl
2015-11-02 11:33 ` Mikael Morin
0 siblings, 1 reply; 3+ messages in thread
From: Steve Kargl @ 2015-11-01 21:16 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 392 bytes --]
The attach patch add checking for a valid type during
matching of a CASE selector. Built and regression
tested on i386-*-freebsd. OK to commit?
2015-11-01 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/68151
* match.c (match_case_selector): Check for invalid type.
2015-11-01 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/68151
* gfortran.dg/pr68151.f90: New test.
--
Steve
[-- Attachment #2: pr68151.diff --]
[-- Type: text/x-diff, Size: 1925 bytes --]
Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c (revision 229634)
+++ gcc/fortran/match.c (working copy)
@@ -5036,6 +5036,15 @@ match_case_selector (gfc_case **cp)
goto need_expr;
if (m == MATCH_ERROR)
goto cleanup;
+
+ /* F08:C830 case-expr shall be of type character, integer, or logical. */
+ if (c->high->ts.type != BT_LOGICAL && c->high->ts.type != BT_INTEGER
+ && c->high->ts.type != BT_CHARACTER)
+ {
+ gfc_error ("Expression in CASE at %L cannot be %s",
+ &c->high->where, gfc_typename (&c->high->ts));
+ goto cleanup;
+ }
}
else
{
@@ -5045,6 +5054,15 @@ match_case_selector (gfc_case **cp)
if (m == MATCH_NO)
goto need_expr;
+ /* F08:C830 case-expr shall be of type character, integer, or logical. */
+ if (c->low->ts.type != BT_LOGICAL && c->low->ts.type != BT_INTEGER
+ && c->low->ts.type != BT_CHARACTER)
+ {
+ gfc_error ("Expression in CASE 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)
Index: gcc/testsuite/gfortran.dg/pr68151.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr68151.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/pr68151.f90 (working copy)
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PR fortran/68151
+! Original code contribute by Gerhard Steinmetz
+! <gerhard dot steinmetz dot fortran at t-online dot de>
+!
+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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PR fortran/68151 -- Check CASE selector for valid type
2015-11-01 21:16 [PATCH] PR fortran/68151 -- Check CASE selector for valid type Steve Kargl
@ 2015-11-02 11:33 ` Mikael Morin
2015-11-02 15:18 ` Steve Kargl
0 siblings, 1 reply; 3+ messages in thread
From: Mikael Morin @ 2015-11-02 11:33 UTC (permalink / raw)
To: Steve Kargl, fortran, gcc-patches
Hello Steve,
Le 01/11/2015 22:16, Steve Kargl a écrit :
> The attach patch add checking for a valid type during
> matching of a CASE selector. Built and regression
> tested on i386-*-freebsd. OK to commit?
[...]
> Index: gcc/fortran/match.c
> ===================================================================
> --- gcc/fortran/match.c (revision 229634)
> +++ gcc/fortran/match.c (working copy)
> @@ -5036,6 +5036,15 @@ match_case_selector (gfc_case **cp)
> goto need_expr;
> if (m == MATCH_ERROR)
> goto cleanup;
> +
> + /* F08:C830 case-expr shall be of type character, integer, or logical. */
case-expr is the expression appearing in a SELECT CASE statement (k in
the test), while here the problem is in a CASE statement, dealing with
value-expr's.
So I think C830 doesn't apply here. But you can rely on F08:C832 saying:
"For a given case-construct, each case-value shall be of the same
type as case-expr"
The type of case-expr is only checked in resolve_select, so the check
for the value-expr's should probably happen there as well.
Mikael
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PR fortran/68151 -- Check CASE selector for valid type
2015-11-02 11:33 ` Mikael Morin
@ 2015-11-02 15:18 ` Steve Kargl
0 siblings, 0 replies; 3+ messages in thread
From: Steve Kargl @ 2015-11-02 15:18 UTC (permalink / raw)
To: Mikael Morin; +Cc: fortran, gcc-patches
On Mon, Nov 02, 2015 at 12:33:25PM +0100, Mikael Morin wrote:
>
> Le 01/11/2015 22:16, Steve Kargl a écrit :
> > The attach patch add checking for a valid type during
> > matching of a CASE selector. Built and regression
> > tested on i386-*-freebsd. OK to commit?
>
> [...]
>
> > Index: gcc/fortran/match.c
> > ===================================================================
> > --- gcc/fortran/match.c (revision 229634)
> > +++ gcc/fortran/match.c (working copy)
> > @@ -5036,6 +5036,15 @@ match_case_selector (gfc_case **cp)
> > goto need_expr;
> > if (m == MATCH_ERROR)
> > goto cleanup;
> > +
> > + /* F08:C830 case-expr shall be of type character, integer, or logical. */
> case-expr is the expression appearing in a SELECT CASE statement (k in
> the test), while here the problem is in a CASE statement, dealing with
> value-expr's.
> So I think C830 doesn't apply here. But you can rely on F08:C832 saying:
> "For a given case-construct, each case-value shall be of the same
> type as case-expr"
> The type of case-expr is only checked in resolve_select, so the check
> for the value-expr's should probably happen there as well.
>
Thanks for the correction. I'll update the comment
and check to see if F08:C832 is enforced
--
Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-11-02 15:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-01 21:16 [PATCH] PR fortran/68151 -- Check CASE selector for valid type Steve Kargl
2015-11-02 11:33 ` Mikael Morin
2015-11-02 15:18 ` Steve Kargl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).