This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, fortran] PR31820 - add warning for implicit conversion of CASE expr


On 05/09/2010 02:26 PM, Daniel Franke wrote:
> As is, gfortran accepts the code below without warning of any kind.
>   INTEGER(KIND=1) :: i
>   SELECT CASE (i)
>     CASE (200)           ! default kind, unreachable for kind=1
>
> Attached patch now adds a warning to raise awareness of the fact. It requires 
> "-Wsurprising -Wconversion" as it is, err, a surprising conversion?!
>
>   select case (i)
>                1
> Warning: SELECT CASE expression at (1) converted from INTEGER(1) to INTEGER(4) 
> as at least one CASE value exceeds the range of INTEGER(1)
>   

Frankly, I do not like neither the -W* options nor the message. I think
the warning should be printed if the case-value exceeds the range of
allowed values of the case-expr. Unless I have misread your patch, you
always print a warning if the value is converted, e.g. also for
   SELECT CASE ( integer_1_expr )
   CASE (1) ! default kind, but in the range of integer(1).

As the case-value is a constant expression, one can check the range
against the range of allowed values of the default kind. Thus, you
should use gfc_check_real_range (real and Re/Im part of complex),
gfc_check_integer_range and print then a warning.


Additionally, one should consider printing the warning by default - but
in any case not hidden by the combination of several warning options.

By the way NAG f95 via the C code it generated has the following GCC
warning (enabled by default):
case.f90:13:1: warning: case label value exceeds maximum value for type
(ifort and g95 print an error message, stating that the case value is
out of range.

By the way, for the program in PR 19168, the case(200) is optimized away
for -O1. The crucial part about that PR was not that the argument has to
be converted to a higher value but that gfortran accepts different
integer kinds without any error or warning. I think even printing an
error for an overflow would be fine - even though not 100% standard
conform. But printing a clear warning does make sense - and I would
argue one should it even print by default.

Tobias

> 2010-05-09  Daniel Franke  <franke.daniel@gmail.com>
>
> 	PR fortran/31820
> 	* resolve.c (resolve_select): Implement FIXME; warn if a case-expr
> 	was promoted to a larger kind.
> 	(validate_case_label_expr): Replaced FIXME with	explanatory note.
> 	* invoke.texi (Wsurprising): Amend the list of surpring constructs.
>
>
> Regression tested on i686-pc-linux-gnu.
> Ok for trunk?
>
> 	Daniel
>   


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]