public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/39666]  New: spurious warning with ranged-switch statements
@ 2009-04-06 18:14 dfranke at gcc dot gnu dot org
  2009-04-28 23:14 ` [Bug middle-end/39666] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 14+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2009-04-06 18:14 UTC (permalink / raw)
  To: gcc-bugs

[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


^ permalink raw reply	[flat|nested] 14+ messages in thread
[parent not found: <bug-39666-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2011-06-27 12:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-06 18:14 [Bug middle-end/39666] New: spurious warning with ranged-switch statements dfranke at gcc dot gnu dot org
2009-04-28 23:14 ` [Bug middle-end/39666] " pinskia at gcc dot gnu dot org
2009-04-29 11:52 ` jakub at gcc dot gnu dot org
2009-04-29 13:54 ` jakub at gcc dot gnu dot org
2009-04-29 14:07 ` [Bug middle-end/39666] [4.3/4.4/4.5 Regression] " jakub at gcc dot gnu dot org
2009-04-29 14:18 ` rguenth at gcc dot gnu dot org
2009-05-05 16:08 ` mmitchel at gcc dot gnu dot org
2009-05-05 21:09 ` jakub at gcc dot gnu dot org
2009-05-12 16:19 ` jakub at gcc dot gnu dot org
2009-05-12 16:24 ` [Bug middle-end/39666] [4.3 " jakub at gcc dot gnu dot org
2009-08-04 12:48 ` rguenth at gcc dot gnu dot org
2009-12-04 22:48 ` dfranke at gcc dot gnu dot org
2010-05-22 18:31 ` rguenth at gcc dot gnu dot org
     [not found] <bug-39666-4@http.gcc.gnu.org/bugzilla/>
2011-06-27 12:03 ` rguenth at gcc dot gnu.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).