invoke.texi (-Wimplicit-fallthrough): Document FALLTHRU comment style changes.

* doc/invoke.texi (-Wimplicit-fallthrough): Document FALLTHRU comment
	style changes.

	* lex.c (fallthrough_comment_p): Extend to handle more common FALLTHRU
	comment styles.

	* c-c++-common/Wimplicit-fallthrough-23.c (foo): Add further tests.

From-SVN: r240885
This commit is contained in:
Jakub Jelinek 2016-10-08 12:53:05 +02:00 committed by Jakub Jelinek
parent 7bad794aa0
commit 81b02905b0
6 changed files with 213 additions and 13 deletions

View File

@ -1,5 +1,8 @@
2016-10-08 Jakub Jelinek <jakub@redhat.com>
* doc/invoke.texi (-Wimplicit-fallthrough): Document FALLTHRU comment
style changes.
* doc/invoke.texi (-Wimplicit-fallthrough): Document the accepted
FALLTHRU comment styles.

View File

@ -4179,11 +4179,13 @@ should match one of the following regular expressions:
@item @code{@@fallthrough@@}
@item @code{[ \t]*FALL(S | |-)?THR(OUGH|U)\.?[ \t]*}
@item @code{lint -fallthrough ?}
@item @code{[ \t]*Fall((s | |-)[Tt]|t)hr(ough|u)\.?[ \t]*}
@item @code{[ \t.!]*(ELSE |INTENTIONAL(LY)? )?FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?}
@item @code{[ \t]*fall(s | |-)?thr(ough|u)\.?[ \t]*}
@item @code{[ \t.!]*(Else |Intentional(ly)? )?Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?}
@item @code{[ \t.!]*([Ee]lse |[Ii]ntentional(ly)? )?fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?}
@end itemize

View File

@ -1,5 +1,7 @@
2016-10-08 Jakub Jelinek <jakub@redhat.com>
* c-c++-common/Wimplicit-fallthrough-23.c (foo): Add further tests.
* c-c++-common/Wimplicit-fallthrough-23.c: New test.
* c-c++-common/Wimplicit-fallthrough-24.c: New test.

View File

@ -21,15 +21,39 @@ foo (int i)
case 4:
bar (4);
break;
case 5:
bar (5); /* { dg-bogus "this statement may \[laf]* through" } */
/* Else Fall-Thru! */
case 6:
bar (6);
break;
case 7:
bar (7); /* { dg-bogus "this statement may \[laf]* through" } */
/* Some comment. */
/* fallthrough. */
/* ... fallthrough ... */
/* Some other comment. */
/* And yet another. */
case 8:
bar (8);
break;
case 9:
bar (9); /* { dg-bogus "this statement may \[laf]* through" } */
/* Intentional Fallthru */
case 10:
bar (10);
break;
case 11:
bar (11); /* { dg-bogus "this statement may \[laf]* through" } */
/* intentionally fall through */
case 12:
bar (12);
break;
case 13:
bar (13); /* { dg-bogus "this statement may \[laf]* through" } */
/* Falls Through - for reasons known only to the author. */
case 14:
bar (14);
break;
case 15:
bar (15); /* { dg-bogus "this statement may \[laf]* through" } */
/*-fallthrough*/
@ -42,12 +66,42 @@ foo (int i)
case 18:
bar (18);
break;
case 19:
bar (19); /* { dg-bogus "this statement may \[laf]* through" } */
/*lint -fallthrough*/
case 20:
bar (20);
break;
case 21:
bar (21); /* { dg-bogus "this statement may \[laf]* through" } */
/*lint -fallthrough */
case 22:
bar (22);
break;
case 23:
bar (23); /* { dg-bogus "this statement may \[laf]* through" } */
/*fallthru*/
case 24:
bar (24);
break;
case 25:
bar (25); /* { dg-bogus "this statement may \[laf]* through" } */
/*Else fallthru*/
case 26:
bar (26);
break;
case 27:
bar (27); /* { dg-bogus "this statement may \[laf]* through" } */
/*Intentional fallthru*/
case 28:
bar (28);
break;
case 29:
bar (29); /* { dg-bogus "this statement may \[laf]* through" } */
/*Intentionally fallthru*/
case 30:
bar (30);
break;
case 31:
bar (31); /* { dg-bogus "this statement may \[laf]* through" } */
/*Falls thru*/
@ -78,15 +132,39 @@ foo (int i)
case 4:
bar (4);
break;
case 5:
bar (5); /* { dg-bogus "this statement may \[laf]* through" } */
// Else Fall-Thru!
case 6:
bar (6);
break;
case 7:
bar (7); /* { dg-bogus "this statement may \[laf]* through" } */
// Some comment.
// fallthrough
// ... fallthrough ...
// Some other comment.
// And yet another.
case 8:
bar (8);
break;
case 9:
bar (9); /* { dg-bogus "this statement may \[laf]* through" } */
// Intentional Fallthru
case 10:
bar (10);
break;
case 11:
bar (11); /* { dg-bogus "this statement may \[laf]* through" } */
// intentionally fall through
case 12:
bar (12);
break;
case 13:
bar (13); /* { dg-bogus "this statement may \[laf]* through" } */
// Falls Through - for reasons known only to the author.
case 14:
bar (14);
break;
case 15:
bar (15); /* { dg-bogus "this statement may \[laf]* through" } */
//-fallthrough
@ -99,12 +177,42 @@ foo (int i)
case 18:
bar (18);
break;
case 19:
bar (19); /* { dg-bogus "this statement may \[laf]* through" } */
//lint -fallthrough
case 20:
bar (20);
break;
case 21:
bar (21); /* { dg-bogus "this statement may \[laf]* through" } */
//lint -fallthrough
case 22:
bar (22);
break;
case 23:
bar (23); /* { dg-bogus "this statement may \[laf]* through" } */
//fallthru
case 24:
bar (24);
break;
case 25:
bar (25); /* { dg-bogus "this statement may \[laf]* through" } */
//Else fallthru
case 26:
bar (26);
break;
case 27:
bar (27); /* { dg-bogus "this statement may \[laf]* through" } */
//Intentional fallthru
case 28:
bar (28);
break;
case 29:
bar (29); /* { dg-bogus "this statement may \[laf]* through" } */
//Intentionally fallthru
case 30:
bar (30);
break;
case 31:
bar (31); /* { dg-bogus "this statement may \[laf]* through" } */
//Falls thru

View File

@ -1,5 +1,8 @@
2016-10-08 Jakub Jelinek <jakub@redhat.com>
* lex.c (fallthrough_comment_p): Extend to handle more common FALLTHRU
comment styles.
* lex.c (fallthrough_comment_p): Fix off-by-one size comparison
errors, cleanup.
(_cpp_lex_direct): Allow arbitrary comments in between

View File

@ -2060,22 +2060,86 @@ fallthrough_comment_p (cpp_reader *pfile, const unsigned char *comment_start)
from += 1 + len;
}
/* Whole comment contents (regex):
[ \t]*FALL(S | |-)?THR(OUGH|U)\.?[ \t]*
[ \t]*Fall((s | |-)[Tt]|t)hr(ough|u)\.?[ \t]*
[ \t]*fall(s | |-)?thr(ough|u)\.?[ \t]*
lint -fallthrough ?
*/
else if (*from == 'l')
{
size_t len = sizeof "int -fallthrough" - 1;
if ((size_t) (pfile->buffer->cur - from - 1) < len)
return false;
if (memcmp (from + 1, "int -fallthrough", len))
return false;
from += 1 + len;
if (*from == ' ')
from++;
}
/* Whole comment contents (regex):
[ \t.!]*(ELSE |INTENTIONAL(LY)? )?FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?
[ \t.!]*(Else |Intentional(ly)? )?Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?
[ \t.!]*([Ee]lse |[Ii]ntentional(ly)? )?fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?
*/
else
{
while (*from == ' ' || *from == '\t')
while (*from == ' ' || *from == '\t' || *from == '.' || *from == '!')
from++;
unsigned char f = *from;
bool all_upper = false;
if (f == 'E' || f == 'e')
{
if ((size_t) (pfile->buffer->cur - from)
< sizeof "else fallthru" - 1)
return false;
if (f == 'E' && memcmp (from + 1, "LSE F", sizeof "LSE F" - 1) == 0)
all_upper = true;
else if (memcmp (from + 1, "lse ", sizeof "lse " - 1))
return false;
from += sizeof "else " - 1;
if (f == 'e' && *from == 'F')
return false;
f = *from;
}
else if (f == 'I' || f == 'i')
{
if ((size_t) (pfile->buffer->cur - from)
< sizeof "intentional fallthru" - 1)
return false;
if (f == 'I' && memcmp (from + 1, "NTENTIONAL",
sizeof "NTENTIONAL" - 1) == 0)
all_upper = true;
else if (memcmp (from + 1, "ntentional",
sizeof "ntentional" - 1))
return false;
from += sizeof "intentional" - 1;
if (*from == ' ')
{
from++;
if (all_upper && *from == 'f')
return false;
}
else if (all_upper)
{
if (memcmp (from, "LY F", sizeof "LY F" - 1))
return false;
from += sizeof "LY " - 1;
}
else
{
if (memcmp (from, "ly ", sizeof "ly " - 1))
return false;
from += sizeof "ly " - 1;
}
if (f == 'i' && *from == 'F')
return false;
f = *from;
}
if (f != 'F' && f != 'f')
return false;
if ((size_t) (pfile->buffer->cur - from) < sizeof "fallthru" - 1)
return false;
bool all_upper = false;
if (f == 'F' && memcmp (from + 1, "ALL", sizeof "ALL" - 1) == 0)
all_upper = true;
else if (all_upper)
return false;
else if (memcmp (from + 1, "all", sizeof "all" - 1))
return false;
from += sizeof "fall" - 1;
@ -2100,10 +2164,28 @@ fallthrough_comment_p (cpp_reader *pfile, const unsigned char *comment_start)
}
else
from += sizeof "thru" - 1;
if (*from == '.')
from++;
while (*from == ' ' || *from == '\t')
while (*from == ' ' || *from == '\t' || *from == '.' || *from == '!')
from++;
if (*from == '-')
{
from++;
if (*comment_start == '*')
{
do
{
while (*from && *from != '*'
&& *from != '\n' && *from != '\r')
from++;
if (*from != '*' || from[1] == '/')
break;
from++;
}
while (1);
}
else
while (*from && *from != '\n' && *from != '\r')
from++;
}
}
/* C block comment. */
if (*comment_start == '*')