Skip to content

Commit 4356eb3

Browse files
Merge pull request #75 from goblint/fallthrough_attribute
Make `__attribute__((__fallthrough__));` no longer parse as declaration
2 parents 5bc7361 + f3111ed commit 4356eb3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/frontc/cparser.mly

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ for_clause:
936936
declaration: /* ISO 6.7.*/
937937
decl_spec_list init_declarator_list SEMICOLON
938938
{ doDeclaration (joinLoc (snd $1) $3) (fst $1) $2 }
939-
| decl_spec_list SEMICOLON
939+
| decl_spec_list_no_attr_only SEMICOLON
940940
{ doDeclaration (joinLoc (snd $1) $2) (fst $1) [] }
941941
| static_assert_declaration { let (e, m, loc) = $1 in STATIC_ASSERT (e, m, loc) }
942942
;
@@ -965,7 +965,7 @@ init_declarator: /* ISO 6.7 */
965965
{ ($1, $3) }
966966
;
967967

968-
decl_spec_list: /* ISO 6.7 */
968+
decl_spec_list_common: /* ISO 6.7 */
969969
/* ISO 6.7.1 */
970970
| TYPEDEF decl_spec_list_opt { SpecTypedef :: $2, $1 }
971971
| EXTERN decl_spec_list_opt { SpecStorage EXTERN :: $2, $1 }
@@ -980,9 +980,17 @@ decl_spec_list: /* ISO 6.7 */
980980
| NORETURN decl_spec_list_opt { SpecNoreturn :: $2, $1 }
981981

982982
| cvspec decl_spec_list_opt { (fst $1) :: $2, snd $1 }
983-
| attribute_nocv decl_spec_list_opt { SpecAttr (fst $1) :: $2, snd $1 }
984983
/* specifier pattern variable (must be last in spec list) */
985984
| AT_SPECIFIER LPAREN IDENT RPAREN { [ SpecPattern(fst $3) ], $1 }
985+
986+
decl_spec_list_no_attr_only:
987+
| decl_spec_list_common { $1 }
988+
| attribute_nocv decl_spec_list { SpecAttr (fst $1) :: (fst $2), snd $1 }
989+
;
990+
991+
decl_spec_list:
992+
| decl_spec_list_common { $1 }
993+
| attribute_nocv decl_spec_list_opt { SpecAttr (fst $1) :: $2, snd $1 }
986994
;
987995
/* (* In most cases if we see a NAMED_TYPE we must shift it. Thus we declare
988996
* NAMED_TYPE to have right associativity *) */

test/small1/fallthrough-label.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ int main() {
33

44
switch(a) {
55
case 5:
6-
__attribute__((__fallthrough__));
6+
a = 8;
7+
__attribute__((__fallthrough__));
8+
case 10:
9+
__attribute__((__fallthrough__));
710
default:
8-
a = 8;
11+
a = 8;
912
}
1013

1114
return 0;

0 commit comments

Comments
 (0)