PR c/71249 73/189273/2
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 24 May 2016 16:22:31 +0000 (16:22 +0000)
committerMikhail Kashkarov <m.kashkarov@partner.samsung.com>
Thu, 18 Oct 2018 13:20:05 +0000 (16:20 +0300)
* gimplify.c (gimplify_switch_expr): Look into the innermost lexical
scope.

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

upstream hash: 6ef0143d8a1ce423db0ae0da55760b4fb82f3bdf
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@236649 138bc75d-0d04-0410-961f-82ee72b054a4

Change-Id: I1270c2aea4e4561f72a9801607bcdfc5edab9a03

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

index 43cf6c0..6c1d994 100644 (file)
@@ -1598,8 +1598,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)
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;
+}