As per GCC's C grammar, the struct-declarator rule has the following productions:
struct-declarator: declarator gnu-attributes[opt] declarator[opt] : constant-expression gnu-attributes[opt] While these productions are handled in the struct_declarator rule of Coccinelle's C grammar, end attributes are not. Add productions for end attributes in the field_declaration rule of Coccinelle's C parser. This parses the following C code from Linux v5.6-rc7 successfully: kernel/sched/sched.h: struct task_group { ... atomic_t load_avg __cacheline_aligned; ... }; Signed-off-by: Jaskaran Singh <jaskaransingh7654...@gmail.com> --- parsing_c/parser_c.mly | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 1ff2fd87..8def5f0d 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -1847,6 +1847,22 @@ field_declaration: *) } + | spec_qualif_list struct_declarator_list end_attributes TPtVirg + { + let (attrs, ds) = $1 in + let (returnType,storage) = fixDeclSpecForDecl ds in + if fst (unwrap storage) <> NoSto + then internal_error "parsing don't allow this"; + + let iistart = Ast_c.fakeInfo () in (* for parallelism with DeclList *) + FieldDeclList ($2 +> (List.map (fun (f, iivirg) -> + f returnType, iivirg)) + ,[$4;iistart]) + (* don't need to check if typedef or func initialised cos + * grammar don't allow typedef nor initialiser in struct + *) + } + | spec_qualif_list TPtVirg { let (attrs, ds) = $1 in @@ -1859,6 +1875,18 @@ field_declaration: FieldDeclList ([(Simple (None, returnType)) , []], [$2;iistart]) } + | spec_qualif_list end_attributes TPtVirg + { + let (attrs, ds) = $1 in + (* gccext: allow empty elements if it is a structdef or enumdef *) + let (returnType,storage) = fixDeclSpecForDecl ds in + if fst (unwrap storage) <> NoSto + then internal_error "parsing don't allow this"; + + let iistart = Ast_c.fakeInfo () in (* for parallelism with DeclList *) + FieldDeclList ([(Simple (None, returnType)) , []], [$3;iistart]) + } + -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci