Skip to content

C front-end: fallthrough attribute, variable aliases #2222

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 2 commits into from
May 22, 2018
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
9 changes: 9 additions & 0 deletions regression/ansi-c/gcc_attributes12/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
static const int my_ids[] = { 1, 2, 3, 4 };

#ifdef __GNUC__
extern typeof(my_ids) my_ids_table __attribute__((alias("my_ids")));
#endif

int main()
{
}
8 changes: 8 additions & 0 deletions regression/ansi-c/gcc_attributes12/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
20 changes: 20 additions & 0 deletions regression/ansi-c/gcc_attributes13/main.c
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions regression/ansi-c/gcc_attributes13/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
2 changes: 1 addition & 1 deletion src/ansi-c/c_typecheck_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void c_typecheck_baset::typecheck_new_symbol(symbolt &symbol)
it->set_identifier(irep_idt());
}
}
else
else if(!symbol.is_macro)
{
// check the initializer
do_initializer(symbol);
Expand Down
10 changes: 10 additions & 0 deletions src/ansi-c/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2156,6 +2157,7 @@ statement:
| msc_asm_statement
| msc_seh_statement
| cprover_exception_statement
| statement_attribute
;

declaration_statement:
Expand Down Expand Up @@ -2214,6 +2216,14 @@ labeled_statement:
}
;

statement_attribute:
TOK_GCC_ATTRIBUTE '(' '(' TOK_GCC_ATTRIBUTE_FALLTHROUGH ')' ')' ';' labeled_statement
{
// attribute ignored
$$=$8;
}
;

compound_statement:
compound_scope '{' '}'
{
Expand Down
2 changes: 2 additions & 0 deletions src/ansi-c/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down