Skip to content

Commit f156ef0

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#2222 from tautschnig/attributes
C front-end: fallthrough attribute, variable aliases
2 parents 376beab + e1b906a commit f156ef0

File tree

7 files changed

+58
-1
lines changed

7 files changed

+58
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
static const int my_ids[] = { 1, 2, 3, 4 };
2+
3+
#ifdef __GNUC__
4+
extern typeof(my_ids) my_ids_table __attribute__((alias("my_ids")));
5+
#endif
6+
7+
int main()
8+
{
9+
}
Lines changed: 8 additions & 0 deletions
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$
Lines changed: 20 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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/c_typecheck_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void c_typecheck_baset::typecheck_new_symbol(symbolt &symbol)
152152
it->set_identifier(irep_idt());
153153
}
154154
}
155-
else
155+
else if(!symbol.is_macro)
156156
{
157157
// check the initializer
158158
do_initializer(symbol);

src/ansi-c/parser.y

Lines changed: 10 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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)