Skip to content

Commit

Permalink
Merge pull request #77 from goblint/allow_attributes_comma_decl
Browse files Browse the repository at this point in the history
Support for comma-separated list of declarations with attributes in non-leading position
  • Loading branch information
michael-schwarz authored Feb 17, 2022
2 parents 4356eb3 + aa156c6 commit 4e2ccf7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/frontc/cparser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,22 @@ static_assert_declaration:
;
init_declarator_list: /* ISO 6.7 */
init_declarator { [$1] }
| init_declarator COMMA init_declarator_list { $1 :: $3 }
| init_declarator COMMA init_declarator_attr_list { $1 :: $3 }
/* Here we disallow attributes for the declarator. Attributes appearing there are parsed as if they belong to the type. */
/* See also https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html */
;

init_declarator_attr_list:
init_declarator_attr { [ $1 ] }
| init_declarator_attr COMMA init_declarator_attr_list { $1 :: $3 }
;

init_declarator_attr:
attribute_nocv_list init_declarator {
let ((name, decl, attrs, loc), init) = $2 in
((name, PARENTYPE ($1,decl,[]), attrs, loc), init)
}
;

;
init_declarator: /* ISO 6.7 */
Expand Down
8 changes: 8 additions & 0 deletions test/small1/attr-in-decllist.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int __attribute__((unused))version,j;
int i, ret, __attribute__((unused))version2, nb_curves;
int i2, ret2, __attribute__((unused))(version3), nb_curves2;
int i3, ret3, (__attribute__((unused))version4), nb_curves3;

int main(void) {
return 0;
}
2 changes: 2 additions & 0 deletions test/testcil.pl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ sub addToGroup {
addTest("testrun/percent400");
addTest("testrun/caserange _GNUCC=1");

addTest("testrun/attr-in-decllist");

addTest("test/attr2 _GNUCC=1");
addTest("test/attr3 _GNUCC=1");
addTest("testrun/attr4 _GNUCC=1");
Expand Down

0 comments on commit 4e2ccf7

Please sign in to comment.