Skip to content

C front-end: fallthrough and __fallthrough__ are the same attribute #5730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions regression/ansi-c/gcc_attributes13/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ int main()
int x;
switch(x)
{
case 1:
x = 2;
case 1:
x = 2;
#ifdef __GNUC__
__attribute__((fallthrough));
__attribute__((fallthrough));
#endif
case 2:
x = 3;
case 2:
{
x = 3;
#ifdef __GNUC__
__attribute__((__fallthrough__));
#endif
}
case 3:
break;
}

return 0;
Expand Down
29 changes: 13 additions & 16 deletions src/ansi-c/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,11 @@ gcc_attribute:
{
init($$);
}
| TOK_GCC_ATTRIBUTE_FALLTHROUGH
{
// attribute ignored
init($$);
}
| gcc_type_attribute
;

Expand Down Expand Up @@ -2320,19 +2325,7 @@ declaration_statement:
;

labeled_statement:
identifier_or_typedef_name ':' gcc_attribute_specifier ';'
{
/* Only semicolons permitted after the attribute:
https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html */
$$=$2;
statement($$, ID_label);
irep_idt identifier=PARSER.lookup_label(parser_stack($1).get(ID_C_base_name));
parser_stack($$).set(ID_label, identifier);
// attribute ignored
statement($3, ID_skip);
mto($$, $3);
}
| identifier_or_typedef_name ':' statement
identifier_or_typedef_name ':' statement
{
$$=$2;
statement($$, ID_label);
Expand Down Expand Up @@ -2367,10 +2360,14 @@ labeled_statement:
;

statement_attribute:
TOK_GCC_ATTRIBUTE '(' '(' TOK_GCC_ATTRIBUTE_FALLTHROUGH ')' ')' ';' labeled_statement
gcc_attribute_specifier ';'
{
// attribute ignored
$$=$8;
// Really should only be TOK_GCC_ATTRIBUTE_FALLTHROUGH or a label
// attribute. Only semicolons permitted after the attribute:
// https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html
// We ignore all such attributes.
$$=$1;
statement($$, ID_skip);
}
;

Expand Down
3 changes: 2 additions & 1 deletion src/ansi-c/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,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; }
"fallthrough" |
"__fallthrough__" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_FALLTHROUGH; }

"used" |
"__used__" { BEGIN(GCC_ATTRIBUTE3); loc(); return TOK_GCC_ATTRIBUTE_USED; }
Expand Down