For the following example from fs/btrfs/ctree.h in Linux v5.6-rc7: __cold __noreturn static inline void assertfail(const char *expr, const char *file, int line) { pr_err("assertion failed: %s, in %s:%d\n", expr, file, line); BUG(); }
__cold and __noreturn are not labeled correctly, leading to C parsing errors. Add a case to commentize attributes before a storage qualifier/type qualifier/type correctly. Signed-off-by: Jaskaran Singh <jaskaransingh7654...@gmail.com> --- parsing_c/parsing_hacks.ml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml index 74c3ba60..0254fc7f 100644 --- a/parsing_c/parsing_hacks.ml +++ b/parsing_c/parsing_hacks.ml @@ -1952,6 +1952,29 @@ let is_type = function | Tshort _ -> true | _ -> false +let is_type_qualif = function + | Tconst _ + | Tvolatile _ -> true + | _ -> false + +let is_storage_spec = function + | Tstatic _ + | Tregister _ + | Textern _ + | Tauto _ -> true + | _ -> false + +let rec is_idents ?(followed_by=fun _ -> true) ts = + let rec loop l = + match l with + | x::xs when ident x -> loop xs + | x::xs -> followed_by x + | [] -> failwith "unexpected end of token stream" in + match ts with + | x::xs when ident x -> loop xs + | x::xs -> followed_by x + | _ -> false + let is_cparen = function (TCPar _) -> true | _ -> false let is_oparen = function (TOPar _) -> true | _ -> false @@ -2134,6 +2157,16 @@ let lookahead2 ~pass next before = else TCommentCpp (Token_c.CppDirective, i1) + (* tt xx yy *) + | (TIdent (s, i1)::rest, _) + when not_struct_enum before + && is_idents + ~followed_by: + (function x -> + is_type x || is_storage_spec x || is_type_qualif x) rest + && s ==~ regexp_annot -> + TCommentCpp (Token_c.CppMacro, i1) + | (TIdent (s2, i2)::_ , TIdent (s, i1)::seen::_) when not_struct_enum before && is_macro s2 && is_type seen -> -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci