Support GCC's fallthrough attribute
This commit is contained in:
parent
d6d0a49b20
commit
e1b906ae4c
|
@ -0,0 +1,20 @@
|
|||
// GCC statement attributes -- currently "fallthrough" is the only one that GCC
|
||||
// supports.
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html
|
||||
|
||||
int main()
|
||||
{
|
||||
int x;
|
||||
switch(x)
|
||||
{
|
||||
case 1:
|
||||
x = 2;
|
||||
#ifdef __GNUC__
|
||||
__attribute__((fallthrough));
|
||||
#endif
|
||||
case 2:
|
||||
x = 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
CORE
|
||||
main.c
|
||||
|
||||
^EXIT=0$
|
||||
^SIGNAL=0$
|
||||
--
|
||||
^warning: ignoring
|
||||
^CONVERSION ERROR$
|
|
@ -148,6 +148,7 @@ extern char *yyansi_ctext;
|
|||
%token TOK_GCC_ATTRIBUTE_NORETURN "noreturn"
|
||||
%token TOK_GCC_ATTRIBUTE_CONSTRUCTOR "constructor"
|
||||
%token TOK_GCC_ATTRIBUTE_DESTRUCTOR "destructor"
|
||||
%token TOK_GCC_ATTRIBUTE_FALLTHROUGH "fallthrough"
|
||||
%token TOK_GCC_LABEL "__label__"
|
||||
%token TOK_MSC_ASM "__asm"
|
||||
%token TOK_MSC_BASED "__based"
|
||||
|
@ -2156,6 +2157,7 @@ statement:
|
|||
| msc_asm_statement
|
||||
| msc_seh_statement
|
||||
| cprover_exception_statement
|
||||
| statement_attribute
|
||||
;
|
||||
|
||||
declaration_statement:
|
||||
|
@ -2214,6 +2216,14 @@ labeled_statement:
|
|||
}
|
||||
;
|
||||
|
||||
statement_attribute:
|
||||
TOK_GCC_ATTRIBUTE '(' '(' TOK_GCC_ATTRIBUTE_FALLTHROUGH ')' ')' ';' labeled_statement
|
||||
{
|
||||
// attribute ignored
|
||||
$$=$8;
|
||||
}
|
||||
;
|
||||
|
||||
compound_statement:
|
||||
compound_scope '{' '}'
|
||||
{
|
||||
|
|
|
@ -1580,6 +1580,8 @@ __decltype { if(PARSER.cpp98 &&
|
|||
"destructor" |
|
||||
"__destructor__" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_DESTRUCTOR; }
|
||||
|
||||
"fallthrough" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_FALLTHROUGH; }
|
||||
|
||||
{ws} { /* ignore */ }
|
||||
{newline} { /* ignore */ }
|
||||
{identifier} { BEGIN(GCC_ATTRIBUTE4); }
|
||||
|
|
Loading…
Reference in New Issue