mirror of git://gcc.gnu.org/git/gcc.git
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
This commit is contained in:
parent
6dc29c6db1
commit
7bad794aa0
|
|
@ -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>
|
2016-10-07 Andrew Pinski <apinski@cavium.com>
|
||||||
|
|
||||||
* config/aarch64/aarch64-arches.def (AARCH64_ARCH): #undef at the end.
|
* config/aarch64/aarch64-arches.def (AARCH64_ARCH): #undef at the end.
|
||||||
|
|
|
||||||
|
|
@ -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>
|
2016-10-07 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
Implement LWG2296 helper intrinsic
|
Implement LWG2296 helper intrinsic
|
||||||
|
|
|
||||||
|
|
@ -596,9 +596,21 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
|
||||||
case CPP_MACRO_ARG:
|
case CPP_MACRO_ARG:
|
||||||
gcc_unreachable ();
|
gcc_unreachable ();
|
||||||
|
|
||||||
/* CPP_COMMENT will appear when compiling with -C and should be
|
/* CPP_COMMENT will appear when compiling with -C. Ignore, except
|
||||||
ignored. */
|
when it is a FALLTHROUGH comment, in that case set
|
||||||
case CPP_COMMENT:
|
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;
|
goto retry;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -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
|
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.
|
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"
|
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,
|
comment to silence the warning. The whole body of the C or C++ style comment
|
||||||
for example all of "Falls through.", "fallthru", "FALLS-THROUGH" work. This
|
should match one of the following regular expressions:
|
||||||
comment needs to consist of two words merely, optionally followed by periods
|
|
||||||
or whitespaces.
|
@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
|
@smallexample
|
||||||
@group
|
@group
|
||||||
|
|
|
||||||
|
|
@ -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>
|
2016-10-07 Fritz Reese <fritzoreese@gmail.com>
|
||||||
|
|
||||||
* gfortran.dg/dec_union_11.f90: New testcase.
|
* gfortran.dg/dec_union_11.f90: New testcase.
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
/* { dg-do compile } */
|
||||||
|
/* { dg-options "-Wimplicit-fallthrough -C" } */
|
||||||
|
|
||||||
|
#include "Wimplicit-fallthrough-23.c"
|
||||||
|
|
@ -1,3 +1,10 @@
|
||||||
|
2016-10-08 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
2016-10-04 Kelvin Nilsen <kelvin@gcc.gnu.org>
|
2016-10-04 Kelvin Nilsen <kelvin@gcc.gnu.org>
|
||||||
|
|
||||||
PR target/77847
|
PR target/77847
|
||||||
|
|
|
||||||
36
libcpp/lex.c
36
libcpp/lex.c
|
|
@ -2061,7 +2061,7 @@ fallthrough_comment_p (cpp_reader *pfile, const unsigned char *comment_start)
|
||||||
}
|
}
|
||||||
/* Whole comment contents (regex):
|
/* Whole comment contents (regex):
|
||||||
[ \t]*FALL(S | |-)?THR(OUGH|U)\.?[ \t]*
|
[ \t]*FALL(S | |-)?THR(OUGH|U)\.?[ \t]*
|
||||||
[ \t]*Fall(s | |-)?[Tt]hr(ough|u)\.?[ \t]*
|
[ \t]*Fall((s | |-)[Tt]|t)hr(ough|u)\.?[ \t]*
|
||||||
[ \t]*fall(s | |-)?thr(ough|u)\.?[ \t]*
|
[ \t]*fall(s | |-)?thr(ough|u)\.?[ \t]*
|
||||||
*/
|
*/
|
||||||
else
|
else
|
||||||
|
|
@ -2071,30 +2071,27 @@ fallthrough_comment_p (cpp_reader *pfile, const unsigned char *comment_start)
|
||||||
unsigned char f = *from;
|
unsigned char f = *from;
|
||||||
if (f != 'F' && f != 'f')
|
if (f != 'F' && f != 'f')
|
||||||
return false;
|
return false;
|
||||||
if ((size_t) (pfile->buffer->cur - from) < sizeof "fallthrough")
|
if ((size_t) (pfile->buffer->cur - from) < sizeof "fallthru" - 1)
|
||||||
return false;
|
return false;
|
||||||
bool all_upper = false;
|
bool all_upper = false;
|
||||||
if (f == 'F' && memcmp (from + 1, "ALL", sizeof "ALL" - 1) == 0)
|
if (f == 'F' && memcmp (from + 1, "ALL", sizeof "ALL" - 1) == 0)
|
||||||
all_upper = true;
|
all_upper = true;
|
||||||
else if (memcmp (from + 1, "all", sizeof "all" - 1))
|
else if (memcmp (from + 1, "all", sizeof "all" - 1))
|
||||||
return false;
|
return false;
|
||||||
if (from[sizeof "fall" - 1] == (all_upper ? 'S' : 's')
|
from += sizeof "fall" - 1;
|
||||||
&& from[sizeof "falls" - 1] == ' ')
|
if (*from == (all_upper ? 'S' : 's') && from[1] == ' ')
|
||||||
from += sizeof "falls " - 1;
|
from += 2;
|
||||||
else if (from[sizeof "fall" - 1] == ' '
|
else if (*from == ' ' || *from == '-')
|
||||||
|| from[sizeof "fall" - 1] == '-')
|
from++;
|
||||||
from += sizeof "fall " - 1;
|
else if (*from != (all_upper ? 'T' : 't'))
|
||||||
else if (from[sizeof "fall" - 1] != (all_upper ? 'T' : 't'))
|
|
||||||
return false;
|
return false;
|
||||||
else
|
|
||||||
from += sizeof "fall" - 1;
|
|
||||||
if ((f == 'f' || *from != 'T') && (all_upper || *from != 't'))
|
if ((f == 'f' || *from != 'T') && (all_upper || *from != 't'))
|
||||||
return false;
|
return false;
|
||||||
if ((size_t) (pfile->buffer->cur - from) < sizeof "thru")
|
if ((size_t) (pfile->buffer->cur - from) < sizeof "thru" - 1)
|
||||||
return false;
|
return false;
|
||||||
if (memcmp (from + 1, all_upper ? "HRU" : "hru", sizeof "hru" - 1))
|
if (memcmp (from + 1, all_upper ? "HRU" : "hru", sizeof "hru" - 1))
|
||||||
{
|
{
|
||||||
if ((size_t) (pfile->buffer->cur - from) < sizeof "through")
|
if ((size_t) (pfile->buffer->cur - from) < sizeof "through" - 1)
|
||||||
return false;
|
return false;
|
||||||
if (memcmp (from + 1, all_upper ? "HROUGH" : "hrough",
|
if (memcmp (from + 1, all_upper ? "HROUGH" : "hrough",
|
||||||
sizeof "hrough" - 1))
|
sizeof "hrough" - 1))
|
||||||
|
|
@ -2399,7 +2396,8 @@ _cpp_lex_direct (cpp_reader *pfile)
|
||||||
{
|
{
|
||||||
cppchar_t c;
|
cppchar_t c;
|
||||||
cpp_buffer *buffer;
|
cpp_buffer *buffer;
|
||||||
const unsigned char *comment_start = NULL;
|
const unsigned char *comment_start;
|
||||||
|
bool fallthrough_comment = false;
|
||||||
cpp_token *result = pfile->cur_token++;
|
cpp_token *result = pfile->cur_token++;
|
||||||
|
|
||||||
fresh_line:
|
fresh_line:
|
||||||
|
|
@ -2427,7 +2425,7 @@ _cpp_lex_direct (cpp_reader *pfile)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (buffer != pfile->buffer)
|
if (buffer != pfile->buffer)
|
||||||
comment_start = NULL;
|
fallthrough_comment = false;
|
||||||
if (!pfile->keep_tokens)
|
if (!pfile->keep_tokens)
|
||||||
{
|
{
|
||||||
pfile->cur_run = &pfile->base_run;
|
pfile->cur_run = &pfile->base_run;
|
||||||
|
|
@ -2536,8 +2534,7 @@ _cpp_lex_direct (cpp_reader *pfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Signal FALLTHROUGH comment followed by another token. */
|
/* Signal FALLTHROUGH comment followed by another token. */
|
||||||
if (comment_start
|
if (fallthrough_comment)
|
||||||
&& fallthrough_comment_p (pfile, comment_start))
|
|
||||||
result->flags |= PREV_FALLTHROUGH;
|
result->flags |= PREV_FALLTHROUGH;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -2624,13 +2621,16 @@ _cpp_lex_direct (cpp_reader *pfile)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fallthrough_comment_p (pfile, comment_start))
|
||||||
|
fallthrough_comment = true;
|
||||||
|
|
||||||
if (!pfile->state.save_comments)
|
if (!pfile->state.save_comments)
|
||||||
{
|
{
|
||||||
result->flags |= PREV_WHITE;
|
result->flags |= PREV_WHITE;
|
||||||
goto update_tokens_line;
|
goto update_tokens_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fallthrough_comment_p (pfile, comment_start))
|
if (fallthrough_comment)
|
||||||
result->flags |= PREV_FALLTHROUGH;
|
result->flags |= PREV_FALLTHROUGH;
|
||||||
|
|
||||||
/* Save the comment as a token in its own right. */
|
/* Save the comment as a token in its own right. */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue