OSDN Git Service

2005-08-22 Andrew Pinski <pinskia@physics.uc.edu>
authorpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 22 Aug 2005 16:21:18 +0000 (16:21 +0000)
committerpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 22 Aug 2005 16:21:18 +0000 (16:21 +0000)
        PR c/18715
        * c-common.c (c_do_switch_warnings): Look for a node where the enum's
        value is inbetween the range if we did not find an exact match.

2005-08-22  Andrew Pinski  <pinskia@physics.uc.edu>

        PR c/18175
        * gcc.dg/switch-warn-3.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@103343 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/switch-warn-3.c [new file with mode: 0644]

index d98726f..8a5e2f0 100644 (file)
@@ -1,3 +1,9 @@
+2005-08-22  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR c/18715
+       * c-common.c (c_do_switch_warnings): Look for a node where the enum's
+       value is inbetween the range if we did not find an exact match.
+
 2005-08-22  Aldy Hernandez  <aldyh@redhat.com>
 
        * doc/invoke.texi (Option Summary): Add ms1 options.
index 0b208fd..6783277 100644 (file)
@@ -3804,7 +3804,32 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
        {
          splay_tree_node node
            = splay_tree_lookup (cases, (splay_tree_key) TREE_VALUE (chain));
-
+         if (!node)
+           {
+             tree low_value = TREE_VALUE (chain);
+             splay_tree_node low_bound;
+             splay_tree_node high_bound;
+             /* Even though there wasn't an exact match, there might be a
+                case range which includes the enumator's value.  */
+             low_bound = splay_tree_predecessor (cases,
+                                                 (splay_tree_key) low_value);
+             high_bound = splay_tree_successor (cases,
+                                                (splay_tree_key) low_value);
+             
+             /* It is smaller than the LOW_VALUE, so there is no need to check
+                unless the LOW_BOUND is in fact itself a case range.  */
+             if (low_bound
+                 && CASE_HIGH ((tree) low_bound->value)
+                 && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
+                                           low_value) >= 0)
+               node = low_bound;
+             /* The low end of that range is bigger than the current value. */
+             else if (high_bound
+                      && (tree_int_cst_compare ((tree) high_bound->key,
+                                                low_value)
+                          <= 0))
+               node = high_bound;
+           }
          if (node)
            {
              /* Mark the CASE_LOW part of the case entry as seen, so
index b85a569..045be39 100644 (file)
@@ -1,3 +1,8 @@
+2005-08-22  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR c/18175
+       * gcc.dg/switch-warn-3.c: New test.
+
 2005-08-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/22233
diff --git a/gcc/testsuite/gcc.dg/switch-warn-3.c b/gcc/testsuite/gcc.dg/switch-warn-3.c
new file mode 100644 (file)
index 0000000..e13b4f5
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-Wswitch-enum" } */
+
+enum a { a0, a1, a2, a3 };
+
+int error(enum a aa)
+{
+  switch ( aa )
+  {
+  case a0 ... a3:
+    return 1;
+  }
+  return 0;
+}