public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type
@ 2007-05-04 16:59 burnus at gcc dot gnu dot org
2007-06-21 17:49 ` [Bug fortran/31820] " dfranke at gcc dot gnu dot org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-05-04 16:59 UTC (permalink / raw)
To: gcc-bugs
integer(kind=1) i ! kind = 1, -128 <= i < 127
select case (i)
case (200) ! kind = 4, unreachable because of range of i
Taken from gfortran.dg/select_5.f90.
This is valid, but one should print a warning. One may also print an error
since having such a case label does not make sense.
NAG f95: warning: case label value exceeds maximum value for type
g95: Error: Integer overflow in CASE statement at (1)
ifort: Error: select_5.f90, line 11: The case-value is out-of-range.
--
Summary: Warning if case label value exceeds maximum value for
type
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: burnus at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
@ 2007-06-21 17:49 ` dfranke at gcc dot gnu dot org
2007-06-21 19:05 ` dfranke at gcc dot gnu dot org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2007-06-21 17:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from dfranke at gcc dot gnu dot org 2007-06-21 17:49 -------
http://gcc.gnu.org/onlinedocs/gfortran/Error-and-Warning-Options.html
-Wsurprising
[...] This currently produces a warning under the following circumstances:
* An INTEGER SELECT construct has a CASE that can never be matched as its
lower value is greater than its upper value.
* A LOGICAL SELECT construct has three CASE statements.
The latter is implemented and gives:
Warning: Logical SELECT CASE block at (1) has more that two cases
but the former?
--
dfranke at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dfranke at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
2007-06-21 17:49 ` [Bug fortran/31820] " dfranke at gcc dot gnu dot org
@ 2007-06-21 19:05 ` dfranke at gcc dot gnu dot org
2007-08-08 17:10 ` fxcoudert at gcc dot gnu dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2007-06-21 19:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from dfranke at gcc dot gnu dot org 2007-06-21 19:05 -------
> * An INTEGER SELECT construct has a CASE that can never be matched as its
> lower value is greater than its upper value.
In these cases, no error is shown (integer(kind=1) :: i):
select case (i)
case (300)
case (301:399)
case (400)
end select
But:
select case (i)
case (400:300)
end select
results in:
case (400:300)
1
Error: Arithmetic overflow converting INTEGER(4) to INTEGER(1) at (1)
(and an "Internal Error" as a follow-up).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
2007-06-21 17:49 ` [Bug fortran/31820] " dfranke at gcc dot gnu dot org
2007-06-21 19:05 ` dfranke at gcc dot gnu dot org
@ 2007-08-08 17:10 ` fxcoudert at gcc dot gnu dot org
2007-08-15 14:39 ` fxcoudert at gcc dot gnu dot org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-08 17:10 UTC (permalink / raw)
To: gcc-bugs
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |fxcoudert at gcc dot gnu dot
|dot org |org
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-08-08 17:10:37
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
` (2 preceding siblings ...)
2007-08-08 17:10 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-15 14:39 ` fxcoudert at gcc dot gnu dot org
2007-10-04 21:59 ` tobi at gcc dot gnu dot org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-15 14:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from fxcoudert at gcc dot gnu dot org 2007-08-15 14:38 -------
(In reply to comment #1)
> * An INTEGER SELECT construct has a CASE that can never be matched as its
> lower value is greater than its upper value.
It is also implemented:
$ cat u1.f90
integer :: i, j
select case (i)
case (251:250)
end select
end
$ gfortran u1.f90 -Wsurprising
u1.f90:3.10:
case (251:250)
1
Warning: Range specification at (1) can never be matched
When an error occurs, though, we will not display the warning, which is fine
IMHO. We still need to add a check for the initial testcase.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
` (3 preceding siblings ...)
2007-08-15 14:39 ` fxcoudert at gcc dot gnu dot org
@ 2007-10-04 21:59 ` tobi at gcc dot gnu dot org
2007-12-08 18:08 ` fxcoudert at gcc dot gnu dot org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: tobi at gcc dot gnu dot org @ 2007-10-04 21:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from tobi at gcc dot gnu dot org 2007-10-04 21:58 -------
It should be sufficient to convert all case-selectors to the same kind as the
case-expression. We should then be giving exactly the same error as g95,
unless I'm missing something.
--
tobi at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tobi at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
` (4 preceding siblings ...)
2007-10-04 21:59 ` tobi at gcc dot gnu dot org
@ 2007-12-08 18:08 ` fxcoudert at gcc dot gnu dot org
2010-05-09 9:12 ` dfranke at gcc dot gnu dot org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-12-08 18:08 UTC (permalink / raw)
To: gcc-bugs
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|fxcoudert at gcc dot gnu dot|unassigned at gcc dot gnu
|org |dot org
Status|ASSIGNED |NEW
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
` (5 preceding siblings ...)
2007-12-08 18:08 ` fxcoudert at gcc dot gnu dot org
@ 2010-05-09 9:12 ` dfranke at gcc dot gnu dot org
2010-05-09 12:59 ` dfranke at gcc dot gnu dot org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-09 9:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from dfranke at gcc dot gnu dot org 2010-05-09 09:11 -------
(In reply to comment #4)
> It should be sufficient to convert all case-selectors to the same kind as the
> case-expression. We should then be giving exactly the same error as g95,
> unless I'm missing something.
This is directly contradicting the conclusion reached in PR19168 where it was
decided that the case-expr should be promoted to the largest kind of the
case-values (short summary: case values shall be of the same type, but only
character expressions are required to be of same kind, hence apply the same
conversion rules as for direct comparison; see F2003, C805 (R808); F2008, C832
(R838)).
In the example below, the comparison done for the IF statement is promoted to
default integer kind (see dump), no warning is generated for the unreachable
branch. Same holds for the equivalent SELECT.
INTEGER(KIND=1) i
i = 100
IF (i == 200) THEN
print *, "unreachable!"
ELSE
print *, "default!"
END IF
SELECT CASE (i)
CASE (200)
print *, "unreachable!"
CASE DEFAULT
print *, "default!"
END SELECT
END
Nonetheless, I also think that it is counter-intuitive. The least that could be
done: add a warning (-Wconversion? -Wsurprising?) before converting the
case-expr, mentioning that at least one case-value has a kind larger than the
case-expressions kind, which thus can not be reached.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
` (6 preceding siblings ...)
2010-05-09 9:12 ` dfranke at gcc dot gnu dot org
@ 2010-05-09 12:59 ` dfranke at gcc dot gnu dot org
2010-05-11 15:43 ` dfranke at gcc dot gnu dot org
2010-05-11 15:46 ` dfranke at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-09 12:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from dfranke at gcc dot gnu dot org 2010-05-09 12:59 -------
(In reply to comment #5)
> Nonetheless, I also think that it is counter-intuitive. The least that could be
> done: add a warning (-Wconversion? -Wsurprising?) before converting the
> case-expr, mentioning that at least one case-value has a kind larger than the
> case-expressions kind, which thus can not be reached.
Suggested patch:
http://gcc.gnu.org/ml/fortran/2010-05/msg00084.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
` (7 preceding siblings ...)
2010-05-09 12:59 ` dfranke at gcc dot gnu dot org
@ 2010-05-11 15:43 ` dfranke at gcc dot gnu dot org
2010-05-11 15:46 ` dfranke at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-11 15:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from dfranke at gcc dot gnu dot org 2010-05-11 15:43 -------
Subject: Bug 31820
Author: dfranke
Date: Tue May 11 15:43:16 2010
New Revision: 159278
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159278
Log:
gcc/fortran/:
2010-05-11 Daniel Franke <franke.daniel@gmail.com>
PR fortran/31820
* resolve.c (validate_case_label_expr): Removed FIXME.
(resolve_select): Raise default warning on case labels out of range
of the case expression.
gcc/testsuite/:
2010-05-11 Daniel Franke <franke.daniel@gmail.com>
PR fortran/31820
* gfortran.dg/select_5.f90: Updated.
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/resolve.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gfortran.dg/select_5.f90
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug fortran/31820] Warning if case label value exceeds maximum value for type
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
` (8 preceding siblings ...)
2010-05-11 15:43 ` dfranke at gcc dot gnu dot org
@ 2010-05-11 15:46 ` dfranke at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-11 15:46 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from dfranke at gcc dot gnu dot org 2010-05-11 15:46 -------
Fixed in trunk. Closing.
--
dfranke at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.6.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31820
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-05-11 15:46 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-04 16:59 [Bug fortran/31820] New: Warning if case label value exceeds maximum value for type burnus at gcc dot gnu dot org
2007-06-21 17:49 ` [Bug fortran/31820] " dfranke at gcc dot gnu dot org
2007-06-21 19:05 ` dfranke at gcc dot gnu dot org
2007-08-08 17:10 ` fxcoudert at gcc dot gnu dot org
2007-08-15 14:39 ` fxcoudert at gcc dot gnu dot org
2007-10-04 21:59 ` tobi at gcc dot gnu dot org
2007-12-08 18:08 ` fxcoudert at gcc dot gnu dot org
2010-05-09 9:12 ` dfranke at gcc dot gnu dot org
2010-05-09 12:59 ` dfranke at gcc dot gnu dot org
2010-05-11 15:43 ` dfranke at gcc dot gnu dot org
2010-05-11 15:46 ` dfranke at gcc dot gnu dot org
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).