diff options
author | Jakub Jelinek <jakub@redhat.com> | 2016-10-08 12:48:54 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2016-10-08 12:48:54 +0200 |
commit | 7bad794aa005aa3ee52fc9c872051d8346c09a24 (patch) | |
tree | dbcbde73147d32631dd626a01571e5964d9ff5fe /gcc | |
parent | 6dc29c6db124fab32ab9b69cfb283e078cc881fc (diff) | |
download | gcc-7bad794aa005aa3ee52fc9c872051d8346c09a24.zip gcc-7bad794aa005aa3ee52fc9c872051d8346c09a24.tar.gz gcc-7bad794aa005aa3ee52fc9c872051d8346c09a24.tar.bz2 |
c-lex.c (c_lex_with_flags): For CPP_COMMENT token with PREV_FALLTHROUGH...
* c-lex.c (c_lex_with_flags) <case CPP_COMMENT>: For CPP_COMMENT
token with PREV_FALLTHROUGH, skip all following CPP_PADDING and
CPP_COMMENT tokens and set add_flags to PREV_FALLTHROUGH afterwards.
* doc/invoke.texi (-Wimplicit-fallthrough): Document the accepted
FALLTHRU comment styles.
* lex.c (fallthrough_comment_p): Fix off-by-one size comparison
errors, cleanup.
(_cpp_lex_direct): Allow arbitrary comments in between
fallthrough_comment_p comment and following token.
* c-c++-common/Wimplicit-fallthrough-23.c: New test.
* c-c++-common/Wimplicit-fallthrough-24.c: New test.
From-SVN: r240884
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-lex.c | 18 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 24 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Wimplicit-fallthrough-23.c | 123 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Wimplicit-fallthrough-24.c | 4 |
7 files changed, 178 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a7d6689..353fdba 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-10-08 Jakub Jelinek <jakub@redhat.com> + + * doc/invoke.texi (-Wimplicit-fallthrough): Document the accepted + FALLTHRU comment styles. + 2016-10-07 Andrew Pinski <apinski@cavium.com> * config/aarch64/aarch64-arches.def (AARCH64_ARCH): #undef at the end. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 52ba9b8..9f6b16d 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2016-10-08 Jakub Jelinek <jakub@redhat.com> + + * c-lex.c (c_lex_with_flags) <case CPP_COMMENT>: For CPP_COMMENT + token with PREV_FALLTHROUGH, skip all following CPP_PADDING and + CPP_COMMENT tokens and set add_flags to PREV_FALLTHROUGH afterwards. + 2016-10-07 Jakub Jelinek <jakub@redhat.com> Implement LWG2296 helper intrinsic diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c index 5c6496e..e3803b0 100644 --- a/gcc/c-family/c-lex.c +++ b/gcc/c-family/c-lex.c @@ -596,9 +596,21 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, case CPP_MACRO_ARG: gcc_unreachable (); - /* CPP_COMMENT will appear when compiling with -C and should be - ignored. */ - case CPP_COMMENT: + /* CPP_COMMENT will appear when compiling with -C. Ignore, except + when it is a FALLTHROUGH comment, in that case set + PREV_FALLTHROUGH flag on the next non-comment token. */ + case CPP_COMMENT: + if (tok->flags & PREV_FALLTHROUGH) + { + do + { + tok = cpp_get_token_with_location (parse_in, loc); + type = tok->type; + } + while (type == CPP_PADDING || type == CPP_COMMENT); + add_flags |= PREV_FALLTHROUGH; + goto retry_after_at; + } goto retry; default: diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 22af6e4..e1a3e5f 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -4170,10 +4170,26 @@ C++17 provides a standard way to suppress the @option{-Wimplicit-fallthrough} warning using @code{[[fallthrough]];} instead of the GNU attribute. In C++11 or C++14 users can use @code{[[gnu::fallthrough]];}, which is a GNU extension. Instead of the these attributes, it is also possible to add a "falls through" -comment to silence the warning. GCC accepts a wide range of such comments, -for example all of "Falls through.", "fallthru", "FALLS-THROUGH" work. This -comment needs to consist of two words merely, optionally followed by periods -or whitespaces. +comment to silence the warning. The whole body of the C or C++ style comment +should match one of the following regular expressions: + +@itemize @bullet + +@item @code{-fallthrough} + +@item @code{@@fallthrough@@} + +@item @code{[ \t]*FALL(S | |-)?THR(OUGH|U)\.?[ \t]*} + +@item @code{[ \t]*Fall((s | |-)[Tt]|t)hr(ough|u)\.?[ \t]*} + +@item @code{[ \t]*fall(s | |-)?thr(ough|u)\.?[ \t]*} + +@end itemize + +and the comment needs to be followed after optional whitespace and other comments +by @code{case} or @code{default} keywords or by a user label that preceeds some +@code{case} or @code{default} label. @smallexample @group diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2214179..1868c4c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-10-08 Jakub Jelinek <jakub@redhat.com> + + * c-c++-common/Wimplicit-fallthrough-23.c: New test. + * c-c++-common/Wimplicit-fallthrough-24.c: New test. + 2016-10-07 Fritz Reese <fritzoreese@gmail.com> * gfortran.dg/dec_union_11.f90: New testcase. diff --git a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-23.c b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-23.c new file mode 100644 index 0000000..137b517 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-23.c @@ -0,0 +1,123 @@ +/* { dg-do compile } */ +/* { dg-options "-Wimplicit-fallthrough" } */ + +void bar (int); + +void +foo (int i) +{ + switch (i) + { + case 1: + bar (1); /* { dg-bogus "this statement may \[laf]* through" } */ + /* FALLTHROUGH */ + case 2: + bar (2); + break; + case 3: + bar (3); /* { dg-bogus "this statement may \[laf]* through" } */ + /* FALLS THRU. */ + /* Some other comment. */ + case 4: + bar (4); + break; + case 7: + bar (7); /* { dg-bogus "this statement may \[laf]* through" } */ + /* Some comment. */ + /* fallthrough. */ + /* Some other comment. */ + /* And yet another. */ + case 8: + bar (8); + break; + case 15: + bar (15); /* { dg-bogus "this statement may \[laf]* through" } */ + /*-fallthrough*/ + case 16: + bar (16); + break; + case 17: + bar (17); /* { dg-bogus "this statement may \[laf]* through" } */ + /*@fallthrough@*/ + case 18: + bar (18); + break; + case 23: + bar (23); /* { dg-bogus "this statement may \[laf]* through" } */ + /*fallthru*/ + case 24: + bar (24); + break; + case 31: + bar (31); /* { dg-bogus "this statement may \[laf]* through" } */ + /*Falls thru*/ + case 32: + bar (32); + break; + case 33: + bar (33); /* { dg-bogus "this statement may \[laf]* through" } */ + /*Fall-through*/ + case 34: + bar (34); + break; + default: + break; + } + switch (i) + { + case 1: + bar (1); /* { dg-bogus "this statement may \[laf]* through" } */ + // FALLTHROUGH + case 2: + bar (2); + break; + case 3: + bar (3); /* { dg-bogus "this statement may \[laf]* through" } */ + // FALLS THRU. + // Some other comment. + case 4: + bar (4); + break; + case 7: + bar (7); /* { dg-bogus "this statement may \[laf]* through" } */ + // Some comment. + // fallthrough + // Some other comment. + // And yet another. + case 8: + bar (8); + break; + case 15: + bar (15); /* { dg-bogus "this statement may \[laf]* through" } */ + //-fallthrough + case 16: + bar (16); + break; + case 17: + bar (17); /* { dg-bogus "this statement may \[laf]* through" } */ + //@fallthrough@ + case 18: + bar (18); + break; + case 23: + bar (23); /* { dg-bogus "this statement may \[laf]* through" } */ + //fallthru + case 24: + bar (24); + break; + case 31: + bar (31); /* { dg-bogus "this statement may \[laf]* through" } */ + //Falls thru + case 32: + bar (32); + break; + case 33: + bar (33); /* { dg-bogus "this statement may \[laf]* through" } */ + //Fall-through + case 34: + bar (34); + break; + default: + break; + } +} diff --git a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-24.c b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-24.c new file mode 100644 index 0000000..15f33c6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-24.c @@ -0,0 +1,4 @@ +/* { dg-do compile } */ +/* { dg-options "-Wimplicit-fallthrough -C" } */ + +#include "Wimplicit-fallthrough-23.c" |