re PR middle-end/71249 (-Wswitch-unreachable false positive for a compound statement...
authorMarek Polacek <polacek@redhat.com>
Tue, 24 May 2016 16:22:31 +0000 (16:22 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 24 May 2016 16:22:31 +0000 (16:22 +0000)
PR c/71249
* gimplify.c (gimplify_switch_expr): Look into the innermost lexical
scope.

* c-c++-common/Wswitch-unreachable-2.c: New test.

From-SVN: r236649

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wswitch-unreachable-2.c [new file with mode: 0644]

index 1b81d4106f838938e1a72921965bcbb5110dfb01..2b20cc81559344bdc4f7566a5ccccbcd75b129f8 100644 (file)
@@ -1,3 +1,9 @@
+2016-05-24  Marek Polacek  <polacek@redhat.com>
+
+       PR c/71249
+       * gimplify.c (gimplify_switch_expr): Look into the innermost lexical
+       scope.
+
 2016-05-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/71257
index e702bc4563ae14c3a415fd68cde3b952186d070d..67394e36407c29e237ac0225ba181879cbea5479 100644 (file)
@@ -1605,8 +1605,9 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p)
          && switch_body_seq != NULL)
        {
          gimple_seq seq = switch_body_seq;
-         if (gimple_code (switch_body_seq) == GIMPLE_BIND)
-           seq = gimple_bind_body (as_a <gbind *> (switch_body_seq));
+         /* Look into the innermost lexical scope.  */
+         while (gimple_code (seq) == GIMPLE_BIND)
+           seq = gimple_bind_body (as_a <gbind *> (seq));
          gimple *stmt = gimple_seq_first_stmt (seq);
          enum gimple_code code = gimple_code (stmt);
          if (code != GIMPLE_LABEL && code != GIMPLE_TRY)
index c0a271cefd9e206369c46851f6a5c15c2c1cc893..e2b2466903c8b50d39964a2360aad9ff69e5c4af 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-24  Marek Polacek  <polacek@redhat.com>
+
+       PR c/71249
+       * c-c++-common/Wswitch-unreachable-2.c: New test.
+
 2016-05-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/71257
diff --git a/gcc/testsuite/c-c++-common/Wswitch-unreachable-2.c b/gcc/testsuite/c-c++-common/Wswitch-unreachable-2.c
new file mode 100644 (file)
index 0000000..8f57392
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR c/71249 */
+/* { dg-do compile } */
+
+int
+f (int i)
+{
+  switch (i)
+    {
+      {
+       int j;
+      foo:
+       return i; /* { dg-bogus "statement will never be executed" } */
+      };
+    case 3:
+      goto foo;
+    }
+  return i;
+}