Skip to content

Commit 5c642fc

Browse files
committed
C front-end: fallthrough and __fallthrough__ are the same attribute
We already supported the former, but were missing the latter form.
1 parent 932599e commit 5c642fc

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

regression/ansi-c/gcc_attributes13/main.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ int main()
77
int x;
88
switch(x)
99
{
10-
case 1:
11-
x = 2;
10+
case 1:
11+
x = 2;
1212
#ifdef __GNUC__
13-
__attribute__((fallthrough));
13+
__attribute__((fallthrough));
1414
#endif
15-
case 2:
16-
x = 3;
15+
case 2:
16+
{
17+
x = 3;
18+
#ifdef __GNUC__
19+
__attribute__((__fallthrough__));
20+
#endif
21+
}
22+
case 3:
23+
break;
1724
}
1825

1926
return 0;

src/ansi-c/parser.y

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,11 @@ gcc_attribute:
16341634
{
16351635
init($$);
16361636
}
1637+
| TOK_GCC_ATTRIBUTE_FALLTHROUGH
1638+
{
1639+
// attribute ignored
1640+
init($$);
1641+
}
16371642
| gcc_type_attribute
16381643
;
16391644

@@ -2299,19 +2304,7 @@ declaration_statement:
22992304
;
23002305

23012306
labeled_statement:
2302-
identifier_or_typedef_name ':' gcc_attribute_specifier ';'
2303-
{
2304-
/* Only semicolons permitted after the attribute:
2305-
https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html */
2306-
$$=$2;
2307-
statement($$, ID_label);
2308-
irep_idt identifier=PARSER.lookup_label(parser_stack($1).get(ID_C_base_name));
2309-
parser_stack($$).set(ID_label, identifier);
2310-
// attribute ignored
2311-
statement($3, ID_skip);
2312-
mto($$, $3);
2313-
}
2314-
| identifier_or_typedef_name ':' statement
2307+
identifier_or_typedef_name ':' statement
23152308
{
23162309
$$=$2;
23172310
statement($$, ID_label);
@@ -2346,10 +2339,14 @@ labeled_statement:
23462339
;
23472340

23482341
statement_attribute:
2349-
TOK_GCC_ATTRIBUTE '(' '(' TOK_GCC_ATTRIBUTE_FALLTHROUGH ')' ')' ';' labeled_statement
2342+
gcc_attribute_specifier ';'
23502343
{
2351-
// attribute ignored
2352-
$$=$8;
2344+
// Really should only be TOK_GCC_ATTRIBUTE_FALLTHROUGH or a label
2345+
// attribute. Only semicolons permitted after the attribute:
2346+
// https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html
2347+
// We ignore all such attributes.
2348+
$$=$1;
2349+
statement($$, ID_skip);
23532350
}
23542351
;
23552352

src/ansi-c/scanner.l

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,8 @@ __decltype { if(PARSER.cpp98 &&
16971697
"destructor" |
16981698
"__destructor__" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_DESTRUCTOR; }
16991699

1700-
"fallthrough" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_FALLTHROUGH; }
1700+
"fallthrough" |
1701+
"__fallthrough__" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_FALLTHROUGH; }
17011702

17021703
"used" |
17031704
"__used__" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_USED; }

0 commit comments

Comments
 (0)