aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-01-20 16:28:16 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-01-20 16:28:16 +0000
commitd2aadab150ac5f2c7e140d5568647a0c74eb67da (patch)
tree2e7dbd0f9a2d2c81943c7cec1e7f5884b0fa0ade /gcc
parent776d540459c10c1cfe407a39f4460c9fe807712f (diff)
downloadgcc-d2aadab150ac5f2c7e140d5568647a0c74eb67da.zip
gcc-d2aadab150ac5f2c7e140d5568647a0c74eb67da.tar.gz
gcc-d2aadab150ac5f2c7e140d5568647a0c74eb67da.tar.bz2
re PR c/79152 (-Wimplicit-fallthrough false positive triggered by goto statements)
PR c/79152 * gimplify.c (should_warn_for_implicit_fallthrough): Handle consecutive non-case labels. * c-c++-common/Wimplicit-fallthrough-35.c: New test. From-SVN: r244726
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/gimplify.c9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c61
4 files changed, 79 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0b3d0c9..67ccfa8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-01-20 Marek Polacek <polacek@redhat.com>
+
+ PR c/79152
+ * gimplify.c (should_warn_for_implicit_fallthrough): Handle consecutive
+ non-case labels.
+
2017-01-20 Alexander Monakov <amonakov@ispras.ru>
* omp-expand.c (expand_omp_simd): Clear PROP_gimple_lomp_dev regardless
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 2777a23..d382eea 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -1985,7 +1985,7 @@ should_warn_for_implicit_fallthrough (gimple_stmt_iterator *gsi_p, tree label)
if (FALLTHROUGH_LABEL_P (label))
return false;
- /* Don't warn for a non-case label followed by a statement:
+ /* Don't warn for non-case labels followed by a statement:
case 0:
foo ();
label:
@@ -1993,7 +1993,12 @@ should_warn_for_implicit_fallthrough (gimple_stmt_iterator *gsi_p, tree label)
as these are likely intentional. */
if (!case_label_p (&gimplify_ctxp->case_labels, label))
{
- gsi_next (&gsi);
+ tree l;
+ while (!gsi_end_p (gsi)
+ && gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL
+ && (l = gimple_label_label (as_a <glabel *> (gsi_stmt (gsi))))
+ && !case_label_p (&gimplify_ctxp->case_labels, l))
+ gsi_next (&gsi);
if (gsi_end_p (gsi) || gimple_code (gsi_stmt (gsi)) != GIMPLE_LABEL)
return false;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cc98016..69ba36c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-01-20 Marek Polacek <polacek@redhat.com>
+
+ PR c/79152
+ * c-c++-common/Wimplicit-fallthrough-35.c: New test.
+
2017-01-20 Thomas Preud'homme <thomas.preudhomme@arm.com>
* lib/target-supports.exp (check_configured_with): New procedure.
diff --git a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c
new file mode 100644
index 0000000..9a0aba6
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c
@@ -0,0 +1,61 @@
+/* PR c/79152 */
+/* { dg-do compile } */
+/* { dg-options "-Wimplicit-fallthrough" } */
+
+extern void foo (int);
+
+void
+f (int i)
+{
+ switch (i)
+ {
+ case 0:
+ foo (0);
+l1:
+ foo (1);
+ }
+
+ switch (i)
+ {
+ case 0:
+ foo (0);
+l2:;
+ }
+
+ switch (i)
+ {
+ case 0:
+ foo (0);
+l3:
+l4:
+ foo (1);
+ }
+
+ switch (i)
+ {
+ case 0:
+ foo (0);
+l5:
+l6:;
+ }
+
+ switch (i)
+ {
+ case 0:
+ foo (0); /* { dg-warning "statement may fall through" } */
+l7:
+l8:
+ case 1:
+ foo (1);
+ }
+
+ switch (i)
+ {
+ case 0:
+ foo (0); /* { dg-warning "statement may fall through" } */
+l9:
+ case 1:
+l10:
+ foo (1);
+ }
+}