As per GCC's C grammar, the struct-or-union-specifier and enum-specifier have the following productions:
struct-or-union-specifier: struct-or-union attribute-specifier-sequence[opt] gnu-attributes[opt] identifier[opt] { struct-contents } gnu-attributes[opt] enum-specifier: enum gnu-attributes[opt] identifier[opt] { enumerator-list } gnu-attributes[opt] enum gnu-attributes[opt] identifier[opt] { enumerator-list , } gnu-attributes[opt] Add a production to the decl2 rule of Coccinelle's C parser to handle the end attributes here (i.e. gnu-attributes after the } ). This parses the following C code from Linux v5.6-rc7: drivers/net/wireless/broadcom/b43legacy/b43legacy.h struct b43legacy_iv { __be16 offset_size; union { __be16 d16; __be32 d32; } data __packed; } __packed; drivers/scsi/myrs.h: enum myrs_cmd_opcode { MYRS_CMD_OP_MEMCOPY = 0x01, MYRS_CMD_OP_SCSI_10_PASSTHRU = 0x02, MYRS_CMD_OP_SCSI_255_PASSTHRU = 0x03, MYRS_CMD_OP_SCSI_10 = 0x04, MYRS_CMD_OP_SCSI_256 = 0x05, MYRS_CMD_OP_IOCTL = 0x20, } __packed; Signed-off-by: Jaskaran Singh <jaskaransingh7654...@gmail.com> --- parsing_c/parser_c.mly | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 5b7e1faf..3412c34e 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -1542,16 +1542,16 @@ abstract_declaratort: /*(*************************************************************************)*/ decl2: - | decl_spec TPtVirg + | decl_spec end_attributes_opt TPtVirg { function local -> let (returnType,storage) = fixDeclSpecForDecl (snd $1) in let iistart = Ast_c.fakeInfo () in DeclList ([{v_namei = None; v_type = returnType; v_storage = unwrap storage; v_local = local; - v_attr = fst $1; v_endattr = Ast_c.noattr; + v_attr = fst $1; v_endattr = $2; v_type_bis = ref None; },[]], - ($2::iistart::snd storage)) + ($3::iistart::snd storage)) } | decl_spec init_declarator_list TPtVirg { function local -> -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci