diff options
author | Marek Polacek <polacek@redhat.com> | 2016-05-31 14:55:05 +0000 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2016-05-31 14:55:05 +0000 |
commit | 2b6ac92f65a69e76293c4a6f12b5c47a7feb0a21 (patch) | |
tree | 3f9f27e01869c122dc7dfd97c20e9ce1fe253901 | |
parent | 65f9b5a3e3e103d1762713951078a1be2869418e (diff) |
* gimplify.c (gimplify_switch_expr): Also handle GIMPLE_TRY.
* c-c++-common/Wswitch-unreachable-3.c: New test.
* g++.dg/warn/Wswitch-unreachable-1.C: New test.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@236924 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/gimplify.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Wswitch-unreachable-3.c | 29 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wswitch-unreachable-1.C | 34 |
5 files changed, 82 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a558a944e5b..59aae29bdc4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2016-05-31 Marek Polacek <polacek@redhat.com> + + * gimplify.c (gimplify_switch_expr): Also handle GIMPLE_TRY. + 2016-05-31 Kyrylo Tkachov <kyrylo.tkachov@arm.com> * config/aarch64/aarch64.c (aarch_macro_fusion_pair_p): Use diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 8316bb8881f..8b7dddca48a 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1609,10 +1609,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/ChangeLog b/gcc/testsuite/ChangeLog index 8c5def43270..a7cf8340d15 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-31 Marek Polacek <polacek@redhat.com> + + * c-c++-common/Wswitch-unreachable-3.c: New test. + * g++.dg/warn/Wswitch-unreachable-1.C: New test. + 2016-05-31 Richard Biener <rguenther@suse.de> PR tree-optimization/71352 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 index 00000000000..c53cb106b21 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wswitch-unreachable-3.c @@ -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 index 00000000000..99d9a833217 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wswitch-unreachable-1.C @@ -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:; + } +} |