* gimplify.c (gimplify_switch_expr): Also handle GIMPLE_TRY. 74/189274/2
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 31 May 2016 14:55:05 +0000 (14:55 +0000)
committerMikhail Kashkarov <m.kashkarov@partner.samsung.com>
Thu, 18 Oct 2018 13:20:05 +0000 (16:20 +0300)
* c-c++-common/Wswitch-unreachable-3.c: New test.
* g++.dg/warn/Wswitch-unreachable-1.C: New test.

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

Change-Id: Ic1e69ef6931e9f4051060cc37bd33c9a86ad2df3

gcc/gimplify.c
gcc/testsuite/c-c++-common/Wswitch-unreachable-3.c [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wswitch-unreachable-1.C [new file with mode: 0644]

index 6c1d994..056d5ef 100644 (file)
@@ -1602,10 +1602,17 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p)
          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)
+         if (gimple_code (stmt) == GIMPLE_TRY)
            {
-             if (code == GIMPLE_GOTO
+             /* A compiler-generated cleanup or a user-written try block.
+                Try to get the first statement in its try-block, for better
+                location.  */
+             if ((seq = gimple_try_eval (stmt)))
+               stmt = gimple_seq_first_stmt (seq);
+           }
+         if (gimple_code (stmt) != GIMPLE_LABEL)
+           {
+             if (gimple_code (stmt) == GIMPLE_GOTO
                  && TREE_CODE (gimple_goto_dest (stmt)) == LABEL_DECL
                  && DECL_ARTIFICIAL (gimple_goto_dest (stmt)))
                /* Don't warn for compiler-generated gotos.  These occur
diff --git a/gcc/testsuite/c-c++-common/Wswitch-unreachable-3.c b/gcc/testsuite/c-c++-common/Wswitch-unreachable-3.c
new file mode 100644 (file)
index 0000000..c53cb10
--- /dev/null
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+
+extern void f (int *);
+
+void
+g (int i)
+{
+  switch (i)
+    {
+      int a[3];
+      __builtin_memset (a, 0, sizeof a); /* { dg-warning "statement will never be executed" } */
+
+    default:
+      f (a);
+    }
+
+  switch (i)
+    {
+      int a[3];
+      int b[3];
+      int c[3];
+      b[1] = 60; /* { dg-warning "statement will never be executed" } */
+
+    default:
+      f (a);
+      f (b);
+      f (c);
+    }
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wswitch-unreachable-1.C b/gcc/testsuite/g++.dg/warn/Wswitch-unreachable-1.C
new file mode 100644 (file)
index 0000000..99d9a83
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-do compile }
+
+extern int j;
+
+void
+f (int i)
+{
+  switch (i) // { dg-warning "statement will never be executed" }
+    {
+      try
+      {
+      }
+      catch (...)
+      {
+      }
+    case 1:;
+    }
+}
+
+void
+g (int i)
+{
+  switch (i)
+    {
+      try
+      {
+       j = 42;  // { dg-warning "statement will never be executed" }
+      }
+      catch (...)
+      {
+      }
+    case 1:;
+    }
+}