[committed] Fix -Wimplicit-fallthrough with [[{,un}likely]] attributes on labels (PR c++/91024)
Jakub Jelinek
jakub@redhat.com
Thu Jun 27 21:28:00 GMT 2019
Hi!
The likely/unlikely C++11 attributes on case labels result in GIMPLE_PREDICT
statements inserted after the label; we should just ignore such statements,
they aren't something executable in between the labels.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk,
queued for backporting to 9.2.
2019-06-27 Jakub Jelinek <jakub@redhat.com>
PR c++/91024
* gimplify.c (collect_fallthrough_labels): Ignore GIMPLE_PREDICT
statements.
* g++.dg/warn/Wimplicit-fallthrough-4.C: New test.
--- gcc/gimplify.c.jj 2019-06-15 09:08:03.383953216 +0200
+++ gcc/gimplify.c 2019-06-27 20:03:31.943295216 +0200
@@ -2120,6 +2120,8 @@ collect_fallthrough_labels (gimple_stmt_
}
else if (gimple_call_internal_p (gsi_stmt (*gsi_p), IFN_ASAN_MARK))
;
+ else if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_PREDICT)
+ ;
else if (!is_gimple_debug (gsi_stmt (*gsi_p)))
prev = gsi_stmt (*gsi_p);
gsi_next (gsi_p);
--- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-4.C.jj 2019-06-27 20:13:08.557572047 +0200
+++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-4.C 2019-06-27 20:14:12.399606229 +0200
@@ -0,0 +1,22 @@
+// PR c++/91024
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wimplicit-fallthrough" }
+
+int
+foo (char c)
+{
+ int result = 0;
+
+ switch (c)
+ {
+ case 'O':
+ case 'K':
+ return result;
+ [[unlikely]] case 'X': // { dg-bogus "this statement may fall through" }
+ case 'x': // { dg-bogus "here" }
+ return result;
+ default:
+ break;
+ }
+ return result;
+}
Jakub
More information about the Gcc-patches
mailing list