aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.c
diff options
context:
space:
mode:
authorMarek Polacek <mpolacek@gcc.gnu.org>2016-05-23 15:37:09 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2016-05-23 15:37:09 +0000
commita7dc5980e91d758905750a5c0a533f689eca355e (patch)
treed51176bb0505d6371f073a25030266ac0a853be1 /gcc/gimplify.c
parent7e5a3c96db2383a41587d6525b4ac9ea1fafe091 (diff)
downloadgcc-a7dc5980e91d758905750a5c0a533f689eca355e.zip
gcc-a7dc5980e91d758905750a5c0a533f689eca355e.tar.gz
gcc-a7dc5980e91d758905750a5c0a533f689eca355e.tar.bz2
re PR c/49859 (gcc could warn about statements between "switch" and first "case")
PR c/49859 * common.opt (Wswitch-unreachable): New option. * doc/invoke.texi: Document -Wswitch-unreachable. * gimplify.c (gimplify_switch_expr): Implement the -Wswitch-unreachable warning. * c-c++-common/Wswitch-unreachable-1.c: New test. * gcc.dg/Wswitch-unreachable-1.c: New test. * c-c++-common/goacc/sb-2.c (void foo): Add dg-warning. * g++.dg/cpp0x/lambda/lambda-switch.C (main): Likewise. * g++.dg/gomp/block-10.C: Likewise. * gcc.dg/gomp/block-10.c: Likewise. * g++.dg/gomp/block-9.C: Likewise. * gcc.dg/gomp/block-9.c: Likewise. * g++.dg/gomp/target-1.C: Likewise. * g++.dg/gomp/target-2.C: Likewise. * gcc.dg/gomp/target-1.c: Likewise. * gcc.dg/gomp/target-2.c: Likewise. * g++.dg/gomp/taskgroup-1.C: Likewise. * gcc.dg/gomp/taskgroup-1.c: Likewise. * gcc.dg/gomp/teams-1.c: Likewise. * g++.dg/gomp/teams-1.C: Likewise. * g++.dg/overload/error3.C: Likewise. * g++.dg/tm/jump1.C: Likewise. * g++.dg/torture/pr40335.C: Likewise. * gcc.dg/c99-vla-jump-5.c: Likewise. * gcc.dg/switch-warn-1.c: Likewise. * gcc.dg/Wjump-misses-init-1.c: Use -Wno-switch-unreachable. * gcc.dg/nested-func-1.c: Likewise. * gcc.dg/pr67784-4.c: Likewise. From-SVN: r236597
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r--gcc/gimplify.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 4a544e3..6473544 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -1595,6 +1595,32 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p)
gimplify_ctxp->case_labels.create (8);
gimplify_stmt (&SWITCH_BODY (switch_expr), &switch_body_seq);
+
+ /* Possibly warn about unreachable statements between switch's
+ controlling expression and the first case. */
+ if (warn_switch_unreachable
+ /* This warning doesn't play well with Fortran when optimizations
+ are on. */
+ && !lang_GNU_Fortran ()
+ && 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));
+ gimple *stmt = gimple_seq_first_stmt (seq);
+ enum gimple_code code = gimple_code (stmt);
+ if (code != GIMPLE_LABEL && code != GIMPLE_TRY)
+ {
+ if (code == 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
+ in Duff's devices, for example. */;
+ else
+ warning_at (gimple_location (stmt), OPT_Wswitch_unreachable,
+ "statement will never be executed");
+ }
+ }
labels = gimplify_ctxp->case_labels;
gimplify_ctxp->case_labels = saved_labels;