From: Marek Polacek Date: Tue, 24 May 2016 16:22:31 +0000 (+0000) Subject: re PR middle-end/71249 (-Wswitch-unreachable false positive for a compound statement... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ef2ec9d9a2c2d7380d2cf992db20cf8599fc0e3d;p=gcc.git re PR middle-end/71249 (-Wswitch-unreachable false positive for a compound statement containing a used label) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1b81d4106f8..2b20cc81559 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-05-24 Marek Polacek + + PR c/71249 + * gimplify.c (gimplify_switch_expr): Look into the innermost lexical + scope. + 2016-05-24 Jakub Jelinek PR c++/71257 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index e702bc4563a..67394e36407 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -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 (switch_body_seq)); + /* Look into the innermost lexical scope. */ + while (gimple_code (seq) == GIMPLE_BIND) + seq = gimple_bind_body (as_a (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/ChangeLog b/gcc/testsuite/ChangeLog index c0a271cefd9..e2b2466903c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-24 Marek Polacek + + PR c/71249 + * c-c++-common/Wswitch-unreachable-2.c: New test. + 2016-05-24 Jakub Jelinek 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 index 00000000000..8f57392d842 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wswitch-unreachable-2.c @@ -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; +}