Skip to content

Commit e1b906a

Browse files
committed
Support GCC's fallthrough attribute
1 parent d6d0a49 commit e1b906a

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// GCC statement attributes -- currently "fallthrough" is the only one that GCC
2+
// supports.
3+
// https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html
4+
5+
int main()
6+
{
7+
int x;
8+
switch(x)
9+
{
10+
case 1:
11+
x = 2;
12+
#ifdef __GNUC__
13+
__attribute__((fallthrough));
14+
#endif
15+
case 2:
16+
x = 3;
17+
}
18+
19+
return 0;
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/ansi-c/parser.y

+10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ extern char *yyansi_ctext;
148148
%token TOK_GCC_ATTRIBUTE_NORETURN "noreturn"
149149
%token TOK_GCC_ATTRIBUTE_CONSTRUCTOR "constructor"
150150
%token TOK_GCC_ATTRIBUTE_DESTRUCTOR "destructor"
151+
%token TOK_GCC_ATTRIBUTE_FALLTHROUGH "fallthrough"
151152
%token TOK_GCC_LABEL "__label__"
152153
%token TOK_MSC_ASM "__asm"
153154
%token TOK_MSC_BASED "__based"
@@ -2156,6 +2157,7 @@ statement:
21562157
| msc_asm_statement
21572158
| msc_seh_statement
21582159
| cprover_exception_statement
2160+
| statement_attribute
21592161
;
21602162

21612163
declaration_statement:
@@ -2214,6 +2216,14 @@ labeled_statement:
22142216
}
22152217
;
22162218

2219+
statement_attribute:
2220+
TOK_GCC_ATTRIBUTE '(' '(' TOK_GCC_ATTRIBUTE_FALLTHROUGH ')' ')' ';' labeled_statement
2221+
{
2222+
// attribute ignored
2223+
$$=$8;
2224+
}
2225+
;
2226+
22172227
compound_statement:
22182228
compound_scope '{' '}'
22192229
{

src/ansi-c/scanner.l

+2
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,8 @@ __decltype { if(PARSER.cpp98 &&
15801580
"destructor" |
15811581
"__destructor__" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_DESTRUCTOR; }
15821582

1583+
"fallthrough" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_FALLTHROUGH; }
1584+
15831585
{ws} { /* ignore */ }
15841586
{newline} { /* ignore */ }
15851587
{identifier} { BEGIN(GCC_ATTRIBUTE4); }

0 commit comments

Comments
 (0)