[Follow-up to http://gcc.gnu.org/ml/gcc/2009-04/msg00175.html]

$ cat range.f90
FUNCTION f(n)
  INTEGER, INTENT(in) :: n
  REAL                :: f

  SELECT CASE (n)
    CASE ( :-1);  f = -1.0
    CASE (0);     f =  0.0
    CASE (1: );   f =  1.0
  END SELECT
END FUNCTION

$> gfortran-svn -c -O -Wall -fdump-tree-original -fdump-tree-optimized
range.f90
range.f90: In function 'f':
range.f90:1: warning: '__result_f' may be used uninitialized in this function

The dump after optimization shows a 'default' clause that is never reached:
<bb 2>:
  switch (*n;) <default: <L6>, case -2147483648 ... -1: <L7>, case 0: L.3, case
1 ... 2147483647: L.4>


If above code is changed to
$ cat range.f90
FUNCTION f(n)
  INTEGER, INTENT(in) :: n
  REAL                :: f

  SELECT CASE (n)
    CASE ( :-1);  f = 0.0     ! was -1.0
    CASE (0);     f = 0.0
    CASE (1: );   f = 0.0     ! was  1.0
  END SELECT
END FUNCTION

$> gfortran-svn -c -O -Wall -fdump-tree-original -fdump-tree-optimized
range.f90
[no warning]

The dump after optimization shows:
f (integer(kind=4) & n)
{
<bb 2>:
  return 0.0;

}

The initial dump has the same structure for both cases (second case shown):
  switch (*n)
    {
      case -2147483648 ... -1:;
      __result_f = 0.0;
      goto L.1;
      case 0:;
      __result_f = 0.0;
      goto L.1;
      case 1 ... 2147483647:;
      __result_f = 0.0;
      goto L.1;
    }
  L.1:;

In the first case, somewhere during optimization a 'default' is added although
the whole range of an INTEGER(kind=4) is covered - which is found in the second
case.


-- 
           Summary: spurious warning with ranged-switch statements
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dfranke at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39666

Reply via email to