aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-02-28 22:29:42 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2019-02-28 22:29:42 +0000
commitcc284d9cf738f0efd4dedd42476da8372d6a38d6 (patch)
treed36b846330e81bbc43a80c1d99385e483956dabf /gcc
parent80d6ca01843d2119c913e3adf27d20204846072f (diff)
downloadgcc-cc284d9cf738f0efd4dedd42476da8372d6a38d6.zip
gcc-cc284d9cf738f0efd4dedd42476da8372d6a38d6.tar.gz
gcc-cc284d9cf738f0efd4dedd42476da8372d6a38d6.tar.bz2
PR c++/87068 - missing diagnostic with fallthrough statement.
* gimplify.c (expand_FALLTHROUGH_r): If IFN_FALLTHROUGH was found at the end of a seq, save its location to walk_stmt_info. (expand_FALLTHROUGH): Warn if IFN_FALLTHROUGH is at the end of a switch. * c-c++-common/Wimplicit-fallthrough-37.c: New test. From-SVN: r269288
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/gimplify.c14
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/Wimplicit-fallthrough-37.c13
4 files changed, 38 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6d91746..3ee6370 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2019-02-28 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87068 - missing diagnostic with fallthrough statement.
+ * gimplify.c (expand_FALLTHROUGH_r): If IFN_FALLTHROUGH was found
+ at the end of a seq, save its location to walk_stmt_info.
+ (expand_FALLTHROUGH): Warn if IFN_FALLTHROUGH is at the end of
+ a switch.
+
2019-02-28 Jan Hubicka <hubicka@ucw.cz>
PR lto/88585
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 7e37e50..983635b 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -2263,7 +2263,7 @@ maybe_warn_implicit_fallthrough (gimple_seq seq)
static tree
expand_FALLTHROUGH_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
- struct walk_stmt_info *)
+ struct walk_stmt_info *wi)
{
gimple *stmt = gsi_stmt (*gsi_p);
@@ -2283,7 +2283,10 @@ expand_FALLTHROUGH_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
{
gsi_remove (gsi_p, true);
if (gsi_end_p (*gsi_p))
- return integer_zero_node;
+ {
+ *static_cast<location_t *>(wi->info) = gimple_location (stmt);
+ return integer_zero_node;
+ }
bool found = false;
location_t loc = gimple_location (stmt);
@@ -2347,8 +2350,15 @@ static void
expand_FALLTHROUGH (gimple_seq *seq_p)
{
struct walk_stmt_info wi;
+ location_t loc;
memset (&wi, 0, sizeof (wi));
+ wi.info = (void *) &loc;
walk_gimple_seq_mod (seq_p, expand_FALLTHROUGH_r, NULL, &wi);
+ if (wi.callback_result == integer_zero_node)
+ /* We've found [[fallthrough]]; at the end of a switch, which the C++
+ standard says is ill-formed; see [dcl.attr.fallthrough]. */
+ warning_at (loc, 0, "attribute %<fallthrough%> not preceding "
+ "a case label or default label");
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8a36b1f..423591d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-28 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87068 - missing diagnostic with fallthrough statement.
+ * c-c++-common/Wimplicit-fallthrough-37.c: New test.
+
2019-02-28 Thomas Schwinge <thomas@codesourcery.com>
Cesar Philippidis <cesar@codesourcery.com>
diff --git a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-37.c b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-37.c
new file mode 100644
index 0000000..644003a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-37.c
@@ -0,0 +1,13 @@
+/* PR c++/87068 */
+/* { dg-do compile } */
+
+void
+f (int n)
+{
+ switch (n)
+ {
+ case 4:
+ ++n;
+ __attribute__((fallthrough)); /* { dg-warning "not preceding" } */
+ }
+}