cocci: Add cast attributes to C and SmPL ASTs
v2 cover cocci: Add cast attributes to C and SmPL ASTs
This patch series aims to add cast attributes to the C and SmPL ASTs, and match them in C source code. This is a continuation of the series "cocci:
Improve C parsing of attributes"[1].
Three test cases are included:
- detect_cast_attr: Test case to detect a parameter attribute.
- remove_cast_attr: Test case to remove a parameter attribute as per the given SmPL.
- remove_cast_attr_allminus: Test case to replace a type in a cast and checking if the attribute is removed as well.
[1]https://www.mail-archive.com/[email protected]/msg07133.html
Changes in v2:
--------------parsing_c: parser: Pass attribute list from type_name
- Warn about dropped attributes in typeof and sizeof productions
parsing_cocci: parser: Parse cast attributes
- Mention in commit message that cast attributes are matched anywhere in a cast.
parsing_cocci: arity: Reflect Cast attributes
- Apply mcode2arity on attributes as well.
parsing_cocci: visitor_ast: Visit cast attributes
- Typo in commit message (AST0 -> AST).
parsing_c: pretty_print_c: Reflect Cast attributes
- Less space in front of [
parsing_c: ast_c: Add Cast attributes
- Switch places of expression and attributes in Cast type.
parsing_c: parser: Parse Cast attributes
- Switch places of expression and attributes in Cast type.
parsing_c: pretty_print_c: Reflect Cast attributes
- Switch places of expression and attributes in Cast type.
- Change printing order of cast elements.
parsing_c: type_annoter_c: Reflect Cast attributes
- Switch places of expression and attributes in Cast type.
parsing_c: visitor_c: Visit Cast attributes
- Switch places of expression and attributes in Cast type.
- Change visitor order of cast elements.
engine: cocci_vs_c: Match Cast attributes
- Switch places of expression and attributes in C AST Cast type.
ocaml: coccilib: Reflect Cast attributes
- Switch places of expression and attributes in C AST Cast type.
Jaskaran Singh (32):
parsing_c: parser: Pass attribute list from type_name
parsing_cocci: ast0_cocci: Add cast attributes
parsing_cocci: parser: Parse cast attributes
parsing_cocci: visitor_ast0: Visit cast attributes
parsing_cocci: unparse_ast0: Reflect cast attributes
parsing_cocci: index: Reflect Cast attributes
parsing_cocci: iso_pattern: Reflect Cast attributes
parsing_cocci: type_infer: Reflect Cast attributes
parsing_cocci: arity: Reflect Cast attributes
parsing_cocci: check_meta: Reflect Cast attributes
parsing_cocci: compute_lines: Reflect Cast attributes
parsing_cocci: context_neg: Reflect Cast attributes
parsing_cocci: single_statement: Reflect Cast attributes
parsing_cocci: ast_cocci: Add cast attributes
parsing_cocci: visitor_ast: Visit cast attributes
parsing_cocci: pretty_print_cocci: Print cast attributes
parsing_cocci: ast0toast: Reflect Cast attributes
parsing_cocci: disjdistr: Reflect Cast attributes
parsing_cocci: unify_ast: Reflect Cast attributes
parsing_c: ast_c: Add Cast attributes
parsing_c: parser: Parse Cast attributes
parsing_c: pretty_print_c: Reflect Cast attributes
parsing_c: type_annoter_c: Reflect Cast attributes
parsing_c: unparse_cocci: Reflect Cast attributes
parsing_c: visitor_c: Visit Cast attributes
engine: check_exhaustive_pattern: Reflect Cast attributes
engine: cocci_vs_c: Match Cast attributes
ocaml: coccilib: Reflect Cast attributes
tools: spgen: Reflect Cast attrs
tests: Add test case to check cast attribute allminus
tests: Add test case to remove cast attributes
tests: Add test case to detect cast attributes
engine/check_exhaustive_pattern.ml | 2 +- engine/cocci_vs_c.ml | 24 +++++++++++++++++------- ocaml/coccilib.mli | 9 +++++---- parsing_c/ast_c.ml | 2 +- parsing_c/ast_c.mli | 2 +- parsing_c/parse_c.ml | 4 +++- parsing_c/parser_c.mly | 27 ++++++++++++++++++--------- parsing_c/pretty_print_c.ml | 7 ++++--- parsing_c/type_annoter_c.ml | 4 ++-- parsing_c/unparse_cocci.ml | 6 ++++-- parsing_c/visitor_c.ml | 11 +++++++++-- parsing_cocci/arity.ml | 8 +++++--- parsing_cocci/ast0_cocci.ml | 4 ++-- parsing_cocci/ast0_cocci.mli | 4 ++-- parsing_cocci/ast0toast.ml | 5 +++-- parsing_cocci/ast_cocci.ml | 4 ++-- parsing_cocci/ast_cocci.mli | 4 ++-- parsing_cocci/check_meta.ml | 3 ++- parsing_cocci/compute_lines.ml | 5 +++-- parsing_cocci/context_neg.ml | 2 +- parsing_cocci/disjdistr.ml | 5 +++-- parsing_cocci/index.ml | 2 +- parsing_cocci/iso_pattern.ml | 12 +++++++++--- parsing_cocci/parser_cocci_menhir.mly | 9 +++++---- parsing_cocci/pretty_print_cocci.ml | 4 +++- parsing_cocci/single_statement.ml | 2 +- parsing_cocci/type_infer.ml | 2 +- parsing_cocci/unify_ast.ml | 6 ++++-- parsing_cocci/unparse_ast0.ml | 4 +++- parsing_cocci/visitor_ast.ml | 10 ++++++---- parsing_cocci/visitor_ast0.ml | 6 ++++-- tests/detect_cast_attr.c | 10 ++++++++++ tests/detect_cast_attr.cocci | 11 +++++++++++ tests/detect_cast_attr.res | 10 ++++++++++ tests/remove_cast_attr.c | 10 ++++++++++ tests/remove_cast_attr.cocci | 10 ++++++++++ tests/remove_cast_attr.res | 10 ++++++++++ tests/remove_cast_attr_allminus.c | 10 ++++++++++ tests/remove_cast_attr_allminus.cocci | 9 +++++++++ tests/remove_cast_attr_allminus.res | 10 ++++++++++ tools/spgen/source/position_generator.ml | 4 ++-- 41 files changed, 219 insertions(+), 74 deletions(-)
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 1/32 parsing_c: parser: Pass attribute list from type_name
To add Cast attributes to the C AST, pass attributes from the type_name rule of the C parser.
--- ocaml/coccilib.mli | 3 ++- parsing_c/parse_c.ml | 4 +++- parsing_c/parser_c.mly | 24 ++++++++++++++++-------- 3 files changed, 21 insertions(+), 10 deletions(-)
ocaml/coccilib.mli +2 -1
@@ -791,7 +791,8 @@ module Parser_c : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.statement val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.expression val type_name : - (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.fullType + (Lexing.lexbuf -> token) -> Lexing.lexbuf -> + Ast_c.attribute list * Ast_c.fullType end module Lexer_c : sig
parsing_c/parse_c.ml +3 -1
@@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s = result (* Please DO NOT remove this code, even though most of it is not used *) -let type_of_string = parse_gen ~cpp:false ~tos:true Parser_c.type_name +let type_of_string s = + let typname = parse_gen ~cpp:false ~tos:true Parser_c.type_name s in + Common.snd typname let statement_of_string = parse_gen ~cpp:false ~tos:false Parser_c.statement let expression_of_string = parse_gen ~cpp:false ~tos:false Parser_c.expr let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false Parser_c.expr
parsing_c/parser_c.mly +16 -8
@@ -665,7 +665,7 @@ let postfakeInfo pii = %type <Ast_c.statement> statement %type <Ast_c.expression> expr -%type <Ast_c.fullType> type_name +%type <Ast_c.attribute list * Ast_c.fullType> type_name %% /*(*************************************************************************)*/
@@ -818,7 +818,7 @@ arith_expr: cast_expr: | unary_expr { $1 } - | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4)) [$1;$3] } + | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4)) [$1;$3] } /* It could be useful to have the following, but there is no place for the attribute in the AST.
@@ -831,7 +831,11 @@ unary_expr: | TDec unary_expr { mk_e(Infix ($2, Dec)) [$1] } | unary_op cast_expr { mk_e(Unary ($2, fst $1)) [snd $1] } | Tsizeof unary_expr { mk_e(SizeOfExpr ($2)) [$1] } - | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType ($3)) [$1;$2;$4] } + | Tsizeof topar2 type_name tcpar2 + { let ret = mk_e(SizeOfType (snd $3)) [$1;$2;$4] in + match (fst $3) with (* warn about dropped attributes *) + [] -> ret + | _ -> warning "attributes found in sizeof(...), dropping" ret } | Tnew new_argument { mk_e(New (None, $2)) [$1] } | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New (Some $3, $5)) [$1; $2; $4] } | Tdelete cast_expr { mk_e(Delete(false, $2)) [$1] }
@@ -897,9 +901,9 @@ postfix_expr: /*(* gccext: also called compound literals *)*/ | topar2 type_name tcpar2 TOBrace TCBrace - { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3] } + { mk_e(Constructor (snd $2, (InitList [], [$4;$5]))) [$1;$3] } | topar2 type_name tcpar2 TOBrace initialize_list gcc_comma_opt_struct TCBrace - { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] } + { mk_e(Constructor (snd $2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] } primary_expr:
@@ -1298,7 +1302,11 @@ type_spec2: Right3 (TypeName (name, Ast_c.noTypedefDef())),[] } | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)), [$1;$2;$4] } - | Ttypeof TOPar type_name TCPar { Right3 (TypeOfType ($3)), [$1;$2;$4] } + | Ttypeof TOPar type_name TCPar + { let ret = Right3 (TypeOfType (snd $3)), [$1;$2;$4] in + match (fst $3) with (* warn about dropped attributes *) + [] -> ret + | _ -> warning "attributes found in typeof(...), dropping" ret } /*(*----------------------------*)*/ /*(* workarounds *)*/
@@ -1531,12 +1539,12 @@ type_qualif_list: type_name: | spec_qualif_list { let (attrs, ds) = $1 in - let (returnType, _) = fixDeclSpecForDecl ds in returnType } + let (returnType, _) = fixDeclSpecForDecl ds in (attrs, returnType) } | spec_qualif_list abstract_declaratort { let (attrs1, ds) = $1 in let (attrs2, fn) = $2 in let (returnType, _) = fixDeclSpecForDecl ds in - fn returnType } + (attrs1@attrs2, fn returnType) }
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 2/32 parsing_cocci: ast0_cocci: Add cast attributes
In reply to Jaskaran SinghAdd cast attributes to AST0 of SmPL. This is a list of attributes in the Cast type of AST0.
--- parsing_cocci/ast0_cocci.ml | 4 ++-- parsing_cocci/ast0_cocci.mli | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
parsing_cocci/ast0_cocci.ml +2 -2
@@ -123,8 +123,8 @@ and base_expression = string mcode (* ] *) | RecordAccess of expression * string mcode (* . *) * ident | RecordPtAccess of expression * string mcode (* -> *) * ident - | Cast of string mcode (* ( *) * typeC * string mcode (* ) *) * - expression + | Cast of string mcode (* ( *) * typeC * attr list * + string mcode (* ) *) * expression | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * typeC * string mcode (* ) *)
parsing_cocci/ast0_cocci.mli +2 -2
@@ -114,8 +114,8 @@ and base_expression = string mcode (* ] *) | RecordAccess of expression * string mcode (* . *) * ident | RecordPtAccess of expression * string mcode (* -> *) * ident - | Cast of string mcode (* ( *) * typeC * string mcode (* ) *) * - expression + | Cast of string mcode (* ( *) * typeC * attr list * + string mcode (* ) *) * expression | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * typeC * string mcode (* ) *)
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 3/32 parsing_cocci: parser: Parse cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL ASTs. Parse these attributes in the SmPL parser and place them in the SmPL AST. The added production only supports attributes after the type and before the expression. However, these attributes are matched anywhere in within a cast.
--- parsing_cocci/parser_cocci_menhir.mly | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
parsing_cocci/parser_cocci_menhir.mly +5 -4
@@ -2176,11 +2176,12 @@ arith_expr_bis: cast_expr(r,pe): unary_expr(r,pe) { $1 } - | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe) - { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t, + | lp=TOPar t=ctype ar=attr_list rp=TCPar e=cast_expr(r,pe) + { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t, ar, P.clt2mcode ")" rp, e)) } - | lp=TOPar t=ctype d=direct_abstract_d rp=TCPar e=cast_expr(r,pe) - { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t, + | lp=TOPar t=ctype d=direct_abstract_d ar=attr_list rp=TCPar + e=cast_expr(r,pe) + { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t, ar, P.clt2mcode ")" rp, e)) } unary_expr(r,pe):
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 4/32 parsing_cocci: visitor_ast0: Visit cast attributes
In reply to Jaskaran SinghCast attributes are added to AST0 of SmPL. Visit these attributes in the AST0 visitor of SmPL.
--- parsing_cocci/visitor_ast0.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
parsing_cocci/visitor_ast0.ml +4 -2
@@ -184,12 +184,14 @@ let visitor mode bind option_default let (ar_n,ar) = string_mcode ar in let (field_n,field) = ident field in (multibind [exp_n;ar_n;field_n], Ast0.RecordPtAccess(exp,ar,field)) - | Ast0.Cast(lp,ty,rp,exp) -> + | Ast0.Cast(lp,ty,attr,rp,exp) -> let (lp_n,lp) = string_mcode lp in let (ty_n,ty) = typeC ty in + let (attr_n,attr) = map_split_bind string_mcode attr in let (rp_n,rp) = string_mcode rp in let (exp_n,exp) = expression exp in - (multibind [lp_n;ty_n;rp_n;exp_n], Ast0.Cast(lp,ty,rp,exp)) + (multibind [lp_n;ty_n;attr_n;rp_n;exp_n], + Ast0.Cast(lp,ty,attr,rp,exp)) | Ast0.SizeOfExpr(szf,exp) -> let (szf_n,szf) = string_mcode szf in let (exp_n,exp) = expression exp in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 5/32 parsing_cocci: unparse_ast0: Reflect cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in unparse_ast0.ml.
--- parsing_cocci/unparse_ast0.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
parsing_cocci/unparse_ast0.ml +3 -1
@@ -221,8 +221,10 @@ let rec expression e = expression exp; mcode print_string pt; ident field | Ast0.RecordPtAccess(exp,ar,field) -> expression exp; mcode print_string ar; ident field - | Ast0.Cast(lp,ty,rp,exp) -> + | Ast0.Cast(lp,ty,attr,rp,exp) -> mcode print_string_box lp; typeC ty; close_box(); + (if not (attr = []) then print_string " "); + print_between (fun _ -> print_string " ") (mcode print_string) attr; mcode print_string rp; expression exp | Ast0.SizeOfExpr(szf,exp) -> mcode print_string szf; expression exp
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 6/32 parsing_cocci: index: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in index.ml.
--- parsing_cocci/index.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/index.ml +1 -1
@@ -61,7 +61,7 @@ let expression e = | Ast0.ArrayAccess(exp1,lb,exp2,rb) -> [27] | Ast0.RecordAccess(exp,pt,field) -> [28] | Ast0.RecordPtAccess(exp,ar,field) -> [29] - | Ast0.Cast(lp,ty,rp,exp) -> [30] + | Ast0.Cast(lp,ty,attr,rp,exp) -> [30] | Ast0.SizeOfExpr(szf,exp) -> [98] (* added after *) | Ast0.SizeOfType(szf,lp,ty,rp) -> [99] (* added after *) | Ast0.TypeExp(ty) -> [123] (* added after *)
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 7/32 parsing_cocci: iso_pattern: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in iso_pattern.ml.
--- parsing_cocci/iso_pattern.ml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
parsing_cocci/iso_pattern.ml +9 -3
@@ -575,7 +575,7 @@ let match_maker checks_needed context_required whencode_allowed = (* all caps is a const *) Str.string_match all_caps nm 0 | _ -> false) - | Ast0.Cast(lp,ty,rp,e) -> matches e + | Ast0.Cast(lp,ty,attr,rp,e) -> matches e | Ast0.SizeOfExpr(se,exp) -> true | Ast0.SizeOfType(se,lp,ty,rp) -> true | Ast0.MetaExpr(nm,_,_,Ast.CONST,p,_bitfield) ->
@@ -586,7 +586,7 @@ let match_maker checks_needed context_required whencode_allowed = let rec matches e = match Ast0.unwrap e with Ast0.Ident(c) -> true - | Ast0.Cast(lp,ty,rp,e) -> matches e + | Ast0.Cast(lp,ty,attr,rp,e) -> matches e | Ast0.MetaExpr(nm,_,_,Ast.ID,p,_bitfield) -> (Ast0.lub_pure p pure) = pure | _ -> false in
@@ -757,10 +757,16 @@ let match_maker checks_needed context_required whencode_allowed = conjunct_many_bindings [check_mcode opa op; match_expr expa expb; match_ident fielda fieldb] - | (Ast0.Cast(lp1,tya,rp1,expa),Ast0.Cast(lp,tyb,rp,expb)) -> + | (Ast0.Cast(lp1,tya,attra,rp1,expa), + Ast0.Cast(lp,tyb,attrb,rp,expb)) -> + if (List.length attra = List.length attrb && + List.fold_left2 (fun p a b -> p && mcode_equal a b) true + attra attrb) + then conjunct_many_bindings [check_mcode lp1 lp; check_mcode rp1 rp; match_typeC tya tyb; match_expr expa expb] + else return false | (Ast0.SizeOfExpr(szf1,expa),Ast0.SizeOfExpr(szf,expb)) -> conjunct_bindings (check_mcode szf1 szf) (match_expr expa expb) | (Ast0.SizeOfType(szf1,lp1,tya,rp1),
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 8/32 parsing_cocci: type_infer: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in type_infer.ml.
--- parsing_cocci/type_infer.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/type_infer.ml +1 -1
@@ -291,7 +291,7 @@ let rec propagate_types env = | Some x -> let ty = Ast0.wrap x in err exp ty "non-structure pointer type in field ref") - | Ast0.Cast(lp,ty,rp,exp) -> Some ty + | Ast0.Cast(lp,ty,attr,rp,exp) -> Some ty | Ast0.SizeOfExpr(szf,exp) -> Some (Ast0.wrap int_type) | Ast0.SizeOfType(szf,lp,ty,rp) -> Some (Ast0.wrap int_type) | Ast0.TypeExp(ty) -> None
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 9/32 parsing_cocci: arity: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in arity.ml.
--- parsing_cocci/arity.ml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
parsing_cocci/arity.ml +5 -3
@@ -254,13 +254,15 @@ let rec top_expression opt_allowed tgt expr = let ar = mcode ar in let field = ident false arity field in make_exp expr tgt arity (Ast0.RecordPtAccess(exp,ar,field)) - | Ast0.Cast(lp,ty,rp,exp) -> - let arity = exp_same (mcode2line lp) [mcode2arity lp;mcode2arity rp] in + | Ast0.Cast(lp,ty,attr,rp,exp) -> + let arity = + exp_same (mcode2line lp) (List.map mcode2arity ([lp] @ attr @ [rp])) in let lp = mcode lp in let ty = typeC arity ty in + let attr = List.map mcode attr in let rp = mcode rp in let exp = expression arity exp in - make_exp expr tgt arity (Ast0.Cast(lp,ty,rp,exp)) + make_exp expr tgt arity (Ast0.Cast(lp,ty,attr,rp,exp)) | Ast0.SizeOfExpr(szf,exp) -> let arity = exp_same (mcode2line szf) [mcode2arity szf] in let szf = mcode szf in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 10/32 parsing_cocci: check_meta: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in check_meta.ml.
--- parsing_cocci/check_meta.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
parsing_cocci/check_meta.ml +2 -1
@@ -172,7 +172,8 @@ let rec expression context old_metas table minus e = | Ast0.RecordPtAccess(exp,ar,field) -> expression ID old_metas table minus exp; ident FIELD old_metas table minus field - | Ast0.Cast(lp,ty,rp,exp) -> + | Ast0.Cast(lp,ty,attr,rp,exp) -> + (* No meta attribute yet *) typeC old_metas table minus ty; expression ID old_metas table minus exp | Ast0.SizeOfExpr(szf,exp) -> expression ID old_metas table minus exp | Ast0.SizeOfType(szf,lp,ty,rp) -> typeC old_metas table minus ty
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 11/32 parsing_cocci: compute_lines: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in compute_lines.ml.
--- parsing_cocci/compute_lines.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/compute_lines.ml +3 -2
@@ -425,11 +425,12 @@ let rec expression e = let ar = normal_mcode ar in let field = ident field in mkres e (Ast0.RecordPtAccess(exp,ar,field)) exp field - | Ast0.Cast(lp,ty,rp,exp) -> + | Ast0.Cast(lp,ty,attr,rp,exp) -> let lp = normal_mcode lp in let exp = expression exp in + let attr = List.map normal_mcode attr in let rp = normal_mcode rp in - mkres e (Ast0.Cast(lp,typeC ty,rp,exp)) (promote_mcode lp) exp + mkres e (Ast0.Cast(lp,typeC ty,attr,rp,exp)) (promote_mcode lp) exp | Ast0.SizeOfExpr(szf,exp) -> let szf = normal_mcode szf in let exp = expression exp in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 12/32 parsing_cocci: context_neg: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in context_neg.ml.
--- parsing_cocci/context_neg.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/context_neg.ml +1 -1
@@ -628,7 +628,7 @@ let rec equal_expression e1 e2 = equal_mcode pt1 pt2 | (Ast0.RecordPtAccess(_,ar1,_),Ast0.RecordPtAccess(_,ar2,_)) -> equal_mcode ar1 ar2 - | (Ast0.Cast(lp1,_,rp1,_),Ast0.Cast(lp2,_,rp2,_)) -> + | (Ast0.Cast(lp1,_,_,rp1,_),Ast0.Cast(lp2,_,_,rp2,_)) -> equal_mcode lp1 lp2 && equal_mcode rp1 rp2 | (Ast0.SizeOfExpr(szf1,_),Ast0.SizeOfExpr(szf2,_)) -> equal_mcode szf1 szf2
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 13/32 parsing_cocci: single_statement: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in single_statement.ml.
--- parsing_cocci/single_statement.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/single_statement.ml +1 -1
@@ -138,7 +138,7 @@ let rec left_expression e = | Ast0.ArrayAccess(exp1,lb,exp2,rb) -> left_expression exp1 | Ast0.RecordAccess(exp,pt,field) -> left_expression exp | Ast0.RecordPtAccess(exp,ar,field) -> left_expression exp - | Ast0.Cast(lp,ty,rp,exp) -> modif_before_mcode lp + | Ast0.Cast(lp,ty,attr,rp,exp) -> modif_before_mcode lp | Ast0.SizeOfExpr(szf,exp) -> modif_before_mcode szf | Ast0.SizeOfType(szf,lp,ty,rp) -> modif_before_mcode szf | Ast0.TypeExp(ty) -> left_typeC ty
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 14/32 parsing_cocci: ast_cocci: Add cast attributes
In reply to Jaskaran SinghAdd cast attributes to the SmPL AST. This is a list of attributes in the Cast type of the SmPL AST.
--- parsing_cocci/ast_cocci.ml | 4 ++-- parsing_cocci/ast_cocci.mli | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
parsing_cocci/ast_cocci.ml +2 -2
@@ -194,8 +194,8 @@ and base_expression = string mcode (* ] *) | RecordAccess of expression * string mcode (* . *) * ident | RecordPtAccess of expression * string mcode (* -> *) * ident - | Cast of string mcode (* ( *) * fullType * string mcode (* ) *) * - expression + | Cast of string mcode (* ( *) * fullType * attr list * + string mcode (* ) *) * expression | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) * fullType * string mcode (* ) *)
parsing_cocci/ast_cocci.mli +2 -2
@@ -178,8 +178,8 @@ and base_expression = string mcode (* ] *) | RecordAccess of expression * string mcode (* . *) * ident | RecordPtAccess of expression * string mcode (* -> *) * ident - | Cast of string mcode (* ( *) * fullType * string mcode (* ) *) * - expression + | Cast of string mcode (* ( *) * fullType * attr list * + string mcode (* ) *) * expression | SizeOfExpr of string mcode (* sizeof *) * expression | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) *
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 15/32 parsing_cocci: visitor_ast: Visit cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Visit these attributes in the SmPL AST visitor.
--- parsing_cocci/visitor_ast.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
parsing_cocci/visitor_ast.ml +6 -4
@@ -198,12 +198,13 @@ let combiner bind option_default let lar = string_mcode ar in let lfield = ident field in multibind [lexp; lar; lfield] - | Ast.Cast(lp,ty,rp,exp) -> + | Ast.Cast(lp,ty,attr,rp,exp) -> let llp = string_mcode lp in let lty = fullType ty in + let lattr = multibind (List.map string_mcode attr) in let lrp = string_mcode rp in let lexp = expression exp in - multibind [llp; lty; lrp; lexp] + multibind [llp; lty; lattr; lrp; lexp] | Ast.SizeOfExpr(szf,exp) -> let lszf = string_mcode szf in let lexp = expression exp in
@@ -1184,12 +1185,13 @@ let rebuilder let lar = string_mcode ar in let lfield = ident field in Ast.RecordPtAccess(lexp, lar, lfield) - | Ast.Cast(lp,ty,rp,exp) -> + | Ast.Cast(lp,ty,attr,rp,exp) -> let llp = string_mcode lp in let lty = fullType ty in + let lattr = List.map string_mcode attr in let lrp = string_mcode rp in let lexp = expression exp in - Ast.Cast(llp, lty, lrp, lexp) + Ast.Cast(llp, lty, lattr, lrp, lexp) | Ast.SizeOfExpr(szf,exp) -> let lszf = string_mcode szf in let lexp = expression exp in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 16/32 parsing_cocci: pretty_print_cocci: Print cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in pretty_print_cocci.ml by printing these attributes.
--- parsing_cocci/pretty_print_cocci.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
parsing_cocci/pretty_print_cocci.ml +3 -1
@@ -249,8 +249,10 @@ let rec expression e = expression exp; mcode print_string pt; ident field | Ast.RecordPtAccess(exp,ar,field) -> expression exp; mcode print_string ar; ident field - | Ast.Cast(lp,ty,rp,exp) -> + | Ast.Cast(lp,ty,attr,rp,exp) -> mcode print_string_box lp; fullType ty; close_box(); + (if not (attr = []) then print_string " "); + print_between print_space (mcode print_string) attr; mcode print_string rp; expression exp | Ast.SizeOfExpr(sizeof,exp) -> mcode print_string sizeof; expression exp
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 17/32 parsing_cocci: ast0toast: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in ast0toast.ml.
--- parsing_cocci/ast0toast.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/ast0toast.ml +3 -2
@@ -439,9 +439,10 @@ and expression e = Ast.RecordAccess(expression exp,mcode pt,ident field) | Ast0.RecordPtAccess(exp,ar,field) -> Ast.RecordPtAccess(expression exp,mcode ar,ident field) - | Ast0.Cast(lp,ty,rp,exp) -> + | Ast0.Cast(lp,ty,attr,rp,exp) -> let allminus = check_allminus.VT0.combiner_rec_expression e in - Ast.Cast(mcode lp,typeC allminus ty,mcode rp,expression exp) + let attr = List.map mcode attr in + Ast.Cast(mcode lp,typeC allminus ty,attr,mcode rp,expression exp) | Ast0.SizeOfExpr(szf,exp) -> Ast.SizeOfExpr(mcode szf,expression exp) | Ast0.SizeOfType(szf,lp,ty,rp) ->
Signature · 6 lines
2.21.1 _______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci
PATCH v2 18/32 parsing_cocci: disjdistr: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in disjdistr.ml.
--- parsing_cocci/disjdistr.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/disjdistr.ml +3 -2
@@ -219,9 +219,10 @@ and disjexp e = | Ast.RecordPtAccess(exp,ar,field) -> disjmult2 (disjexp exp) (disjident field) (fun exp field -> Ast.rewrap e (Ast.RecordPtAccess(exp,ar,field))) - | Ast.Cast(lp,ty,rp,exp) -> + | Ast.Cast(lp,ty,attr,rp,exp) -> disjmult2 (disjty ty) (disjexp exp) - (function ty -> function exp -> Ast.rewrap e (Ast.Cast(lp,ty,rp,exp))) + (function ty -> function exp -> + Ast.rewrap e (Ast.Cast(lp,ty,attr,rp,exp))) | Ast.SizeOfExpr(szf,exp) -> let exp = disjexp exp in List.map (function exp -> Ast.rewrap e (Ast.SizeOfExpr(szf,exp))) exp
Signature · 6 lines
2.21.1 _______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci
PATCH v2 19/32 parsing_cocci: unify_ast: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in unify_ast.ml.
--- parsing_cocci/unify_ast.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
parsing_cocci/unify_ast.ml +4 -2
@@ -220,8 +220,10 @@ and unify_expression e1 e2 = unify_expression e1 e2 && unify_ident fld1 fld2 | (Ast.RecordPtAccess(e1,pt1,fld1),Ast.RecordPtAccess(e2,pt2,fld2)) -> unify_expression e1 e2 && unify_ident fld1 fld2 - | (Ast.Cast(lp1,ty1,rp1,e1),Ast.Cast(lp2,ty2,rp2,e2)) -> - unify_fullType ty1 ty2 && unify_expression e1 e2 + | (Ast.Cast(lp1,ty1,attr1,rp1,e1),Ast.Cast(lp2,ty2,attr2,rp2,e2)) -> + if List.for_all2 unify_mcode attr1 attr2 + then unify_fullType ty1 ty2 && unify_expression e1 e2 + else false | (Ast.SizeOfExpr(szf1,e1),Ast.SizeOfExpr(szf2,e2)) -> unify_expression e1 e2 | (Ast.SizeOfType(szf1,lp1,ty1,rp1),Ast.SizeOfType(szf2,lp2,ty2,rp2)) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 20/32 parsing_c: ast_c: Add Cast attributes
In reply to Jaskaran SinghAdd cast attributes to the C AST. This is a list of attributes in the Cast type of the C AST.
--- parsing_c/ast_c.ml | 2 +- parsing_c/ast_c.mli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
parsing_c/ast_c.ml +1 -1
@@ -343,7 +343,7 @@ and expression = (expressionbis * exp_info ref (* semantic: *)) wrap3 | SizeOfExpr of expression | SizeOfType of fullType - | Cast of fullType * expression + | Cast of fullType * attribute list * expression (* gccext: *) | StatementExpr of compound wrap (* ( ) new scope *)
parsing_c/ast_c.mli +1 -1
@@ -104,7 +104,7 @@ and expressionbis = | RecordPtAccess of expression * name | SizeOfExpr of expression | SizeOfType of fullType - | Cast of fullType * expression + | Cast of fullType * attribute list * expression | StatementExpr of compound wrap | Constructor of fullType * initialiser | ParenExpr of expression
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 21/32 parsing_c: parser: Parse Cast attributes
In reply to Jaskaran SinghCast attributes are added to the C AST. Parse cast attributes in the C parser and place them in the C AST. The attributes are taken from the type_name rule of the C parser.
--- parsing_c/parser_c.mly | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
parsing_c/parser_c.mly +2 -1
@@ -818,7 +818,8 @@ arith_expr: cast_expr: | unary_expr { $1 } - | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4)) [$1;$3] } + | topar2 type_name tcpar2 cast_expr + { mk_e(Cast (snd $2, fst $2, $4)) [$1;$3] } /* It could be useful to have the following, but there is no place for the attribute in the AST.
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 22/32 parsing_c: pretty_print_c: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Print these attributes in pretty_print_c.ml.
--- parsing_c/pretty_print_c.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
parsing_c/pretty_print_c.ml +4 -3
@@ -146,8 +146,9 @@ let mk_pretty_printers pp_expression e | SizeOfType (t), [i1;i2;i3] -> pr_elem i1; pr_elem i2; pp_type t; pr_elem i3 - | Cast (t, e), [i1;i2] -> - pr_elem i1; pp_type t; pr_elem i2; pp_expression e + | Cast (t, a, e), [i1;i2] -> + pr_elem i1; pp_type t; a +> pp_attributes pr_elem pr_space; + pr_elem i2; pp_expression e; | StatementExpr (statxs, [ii1;ii2]), [i1;i2] -> pr_elem i1;
@@ -184,7 +185,7 @@ let mk_pretty_printers | CondExpr (_,_,_) | Sequence (_,_) | Assignment (_,_,_) | Postfix (_,_) | Infix (_,_) | Unary (_,_) | Binary (_,_,_) | ArrayAccess (_,_) | RecordAccess (_,_) | RecordPtAccess (_,_) - | SizeOfExpr (_) | SizeOfType (_) | Cast (_,_) + | SizeOfExpr (_) | SizeOfType (_) | Cast (_,_,_) | StatementExpr (_) | Constructor _ | ParenExpr (_) | New (_) | Delete (_,_) | Defined (_)),_ -> raise (Impossible 95)
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 23/32 parsing_c: type_annoter_c: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in type_annoter_c.ml.
--- parsing_c/type_annoter_c.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
parsing_c/type_annoter_c.ml +2 -2
@@ -525,7 +525,7 @@ let rec is_simple_expr expr = true | Binary (e1, op, e2) -> true - | Cast (t, e) -> + | Cast (t, a, e) -> true | ParenExpr (e) -> is_simple_expr e
@@ -961,7 +961,7 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr -> (* -------------------------------------------------- *) - | Cast (t, e) -> + | Cast (t, e, a) -> k expr; (* todo: if infer, can "push" info ? add_types_expr [t] e ? *) make_info_def_fix (Lib.al_type t)
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 24/32 parsing_c: unparse_cocci: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in unparse_cocci.ml.
--- parsing_c/unparse_cocci.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
parsing_c/unparse_cocci.ml +4 -2
@@ -455,7 +455,7 @@ let rec expression e = | Ast_c.RecordPtAccess (e, name) -> postfix | Ast_c.SizeOfExpr (e) -> unary | Ast_c.SizeOfType (t) -> unary - | Ast_c.Cast (t, e) -> cast + | Ast_c.Cast (t, a, e) -> cast | Ast_c.StatementExpr (statxs, _) -> top | Ast_c.Constructor (t, init) -> unary | Ast_c.ParenExpr (e) -> primary
@@ -503,8 +503,10 @@ let rec expression e = loop exp postfix; mcode print_string pt; ident field | Ast.RecordPtAccess(exp,ar,field) -> loop exp postfix; mcode print_string ar; ident field - | Ast.Cast(lp,ty,rp,exp) -> + | Ast.Cast(lp,ty,attr,rp,exp) -> mcode print_string_box lp; fullType ty; close_box(); + (if not (attr = []) then pr_space()); + print_between pr_space (mcode print_string) attr; mcode print_string rp; loop exp cast | Ast.SizeOfExpr(sizeof,exp) -> mcode print_string sizeof; loop exp unary
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 25/32 parsing_c: visitor_c: Visit Cast attributes
In reply to Jaskaran SinghCast attributes are added to the C AST. Visit these attributes in the C AST visitor.
--- parsing_c/visitor_c.ml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
parsing_c/visitor_c.ml +9 -2
@@ -324,7 +324,10 @@ let rec vk_expr = fun bigf expr -> | SizeOfExpr (e) -> exprf e | SizeOfType (t) -> vk_type bigf t - | Cast (t, e) -> vk_type bigf t; exprf e + | Cast (t, a, e) -> + vk_type bigf t; + a +> List.iter (vk_attribute bigf); + exprf e (* old: | StatementExpr (((declxs, statxs), is)), is2 -> * List.iter (vk_decl bigf) declxs;
@@ -1188,7 +1191,11 @@ let rec vk_expr_s = fun bigf expr -> | SizeOfExpr (e) -> SizeOfExpr (exprf e) | SizeOfType (t) -> SizeOfType (vk_type_s bigf t) - | Cast (t, e) -> Cast (vk_type_s bigf t, exprf e) + | Cast (t, a, e) -> + Cast + (vk_type_s bigf t, + a +> List.map (vk_attribute_s bigf), + exprf e) | StatementExpr (statxs, is) -> StatementExpr (
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 26/32 engine: check_exhaustive_pattern: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in check_exhaustive_pattern.ml.
--- engine/check_exhaustive_pattern.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
engine/check_exhaustive_pattern.ml +1 -1
@@ -123,7 +123,7 @@ let dumb_astcocci_expr = function | A.ArrayAccess (ea1, _, ea2, _) -> () | A.RecordAccess (ea, _, ida) -> () | A.RecordPtAccess (ea, _, ida) -> () - | A.Cast (_, typa, _, ea) -> () + | A.Cast (_, typa, attra, _, ea) -> () | A.SizeOfExpr (_, ea) -> () | A.SizeOfType (_, _, typa, _) -> () | A.TypeExp (typa) -> ()
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 27/32 engine: cocci_vs_c: Match Cast attributes
In reply to Jaskaran SinghCast attributes are added to the C and SmPL ASTs. Match these attributes in cocci_vs_c.ml.
--- engine/cocci_vs_c.ml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
engine/cocci_vs_c.ml +17 -7
@@ -1121,7 +1121,7 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = * differentiate between different cases *) let rec matches_id = function B.Ident(name) -> true - | B.Cast(ty,e) -> matches_id (B.unwrap_expr e) + | B.Cast(ty,a,e) -> matches_id (B.unwrap_expr e) | _ -> false in let form_ok = match (form,expr) with
@@ -1137,7 +1137,7 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = true end else false - | B.Cast(ty,e) -> matches (B.unwrap_expr e) + | B.Cast(ty,a,e) -> matches (B.unwrap_expr e) | B.Unary(e,B.UnMinus) -> matches (B.unwrap_expr e) | B.SizeOfExpr(exp) -> true | B.SizeOfType(ty) -> true
@@ -1525,16 +1525,26 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = * by trying | ea, B.Case (typb, eb) -> match_e_e ea eb ? *) - | A.Cast (ia1, typa, ia2, ea), ((B.Cast (typb, eb), typ),ii) -> + | A.Cast (ia1, typa, attrsa, ia2, ea), + ((B.Cast (typb, attrsb, eb), typ),ii) -> + + let attr_allminus = + let mcode_is_not_context = function + | (_,_,A.CONTEXT(_,_),_) -> false + | _ -> true in + check_allminus.Visitor_ast.combiner_fullType typa && + List.for_all mcode_is_not_context attrsa in + let (ib1, ib2) = tuple_of_list2 ii in fullType typa typb >>= (fun typa typb -> + attribute_list attr_allminus attrsa attrsb >>= (fun attrsa attrsb -> expression ea eb >>= (fun ea eb -> tokenf ia1 ib1 >>= (fun ia1 ib1 -> tokenf ia2 ib2 >>= (fun ia2 ib2 -> return ( - ((A.Cast (ia1, typa, ia2, ea))) +> wa, - ((B.Cast (typb, eb),typ),[ib1;ib2]) - ))))) + ((A.Cast (ia1, typa, attrsa, ia2, ea))) +> wa, + ((B.Cast (typb, attrsb, eb),typ),[ib1;ib2]) + )))))) | A.SizeOfExpr (ia1, ea), ((B.SizeOfExpr (eb), typ),ii) -> let ib1 = tuple_of_list1 ii in
@@ -1641,7 +1651,7 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = | _, - (((B.Cast (_, _)|B.ParenExpr _|B.SizeOfType _|B.SizeOfExpr _| + (((B.Cast (_, _, _)|B.ParenExpr _|B.SizeOfType _|B.SizeOfExpr _| B.Constructor (_, _)| B.RecordPtAccess (_, _)| B.RecordAccess (_, _)|B.ArrayAccess (_, _)|
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 28/32 ocaml: coccilib: Reflect Cast attributes
In reply to Jaskaran SinghCast attributes are added to the C and SmPL ASTs. Reflect these changes in coccilib.mli.
--- ocaml/coccilib.mli | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
ocaml/coccilib.mli +3 -3
@@ -146,7 +146,7 @@ module Ast_c : | RecordPtAccess of expression * name | SizeOfExpr of expression | SizeOfType of fullType - | Cast of fullType * expression + | Cast of fullType * attribute list * expression | StatementExpr of compound wrap | Constructor of fullType * initialiser | ParenExpr of expression
@@ -2569,7 +2569,7 @@ module Ast_cocci : | ArrayAccess of expression * string mcode * expression * string mcode | RecordAccess of expression * string mcode * ident | RecordPtAccess of expression * string mcode * ident - | Cast of string mcode * fullType * string mcode * expression + | Cast of string mcode * fullType * attr list * string mcode * expression | SizeOfExpr of string mcode * expression | SizeOfType of string mcode * string mcode * fullType * string mcode | TypeExp of fullType
@@ -3305,7 +3305,7 @@ module Ast0_cocci : | ArrayAccess of expression * string mcode * expression * string mcode | RecordAccess of expression * string mcode * ident | RecordPtAccess of expression * string mcode * ident - | Cast of string mcode * typeC * string mcode * expression + | Cast of string mcode * typeC * attr list * string mcode * expression | SizeOfExpr of string mcode * expression | SizeOfType of string mcode * string mcode * typeC * string mcode | TypeExp of typeC
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 29/32 tools: spgen: Reflect Cast attrs
In reply to Jaskaran SinghCast attributes are added to the SmPL AST. Reflect these changes in position_generator.ml.
--- tools/spgen/source/position_generator.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/spgen/source/position_generator.ml +2 -2
@@ -359,9 +359,9 @@ let rec expression_pos exp snp let c ~exp ~id = Ast0.RecordPtAccess(exp, arrow, id) in let alt() = id_wrap ~id ~constructor:(c ~exp) snp in exp_wrap ~exp ~constructor:(c ~id) ~alt snp - | Ast0.Cast(lp, typec, rp, exp) -> + | Ast0.Cast(lp, typec, attr, rp, exp) -> let _ = type_pos typec snp in (* sanity check for disj *) - let c ~exp ~mc = Ast0.Cast(lp, typec, mc, exp) in + let c ~exp ~mc = Ast0.Cast(lp, typec, attr, mc, exp) in let alt() = mcode_wrap ~mc:rp ~constructor:(c ~exp) snp in exp_wrap ~exp ~constructor:(c ~mc:rp) ~alt snp | Ast0.SizeOfExpr(sizeofmc, exp) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 30/32 tests: Add test case to check cast attribute allminus
In reply to Jaskaran SinghAdd a test case to check allminus for cast attributes. The test case replaces all the cast types in the C program. Cases covered are for when the attribute is:
- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.
--- tests/remove_cast_attr_allminus.c | 10 ++++++++++ tests/remove_cast_attr_allminus.cocci | 9 +++++++++ tests/remove_cast_attr_allminus.res | 10 ++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/remove_cast_attr_allminus.c create mode 100644 tests/remove_cast_attr_allminus.cocci create mode 100644 tests/remove_cast_attr_allminus.res
tests/remove_cast_attr_allminus.c new file +10 -0
@@ -0,0 +1,10 @@ +#define __cast_attr MACROANNOTATION + +int func () +{ + int *a = (int __cast_attr) x; + int *a = (__cast_attr int) x; + int *a = (int __cast_attr *) x; + int *a = (int *__cast_attr) x; +int *a = (int ) x; +}
tests/remove_cast_attr_allminus.cocci new file +9 -0
@@ -0,0 +1,9 @@ +@r0@ +type T; +identifier x; +@@ + + ( +- T ++ int * + ) x
tests/remove_cast_attr_allminus.res new file +10 -0
@@ -0,0 +1,10 @@ +#define __cast_attr MACROANNOTATION + +int func() +{ + int *a = (int *) x; + int *a = (int *) x; + int *a = (int *) x; + int *a = (int *) x; + int *a = (int *) x; +}
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v2 31/32 tests: Add test case to remove cast attributes
In reply to Jaskaran SinghAdd a test case to remove a cast attribute. The following cases are covered for when a attribute is:
- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.
--- tests/remove_cast_attr.c | 10 ++++++++++ tests/remove_cast_attr.cocci | 10 ++++++++++ tests/remove_cast_attr.res | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/remove_cast_attr.c create mode 100644 tests/remove_cast_attr.cocci create mode 100644 tests/remove_cast_attr.res
tests/remove_cast_attr.c new file +10 -0
@@ -0,0 +1,10 @@ +#define __cast_attr MACROANNOTATION + +int func () +{ + int *a = (int __cast_attr) x; + int *a = (__cast_attr int) x; + int *a = (int __cast_attr *) x; + int *a = (int *__cast_attr) x; +int *a = (int ) x; +}
tests/remove_cast_attr.cocci new file +10 -0
@@ -0,0 +1,10 @@ +@r0@ +type T; +attribute name __cast_attr; +identifier x; +@@ + + ( + T +- __cast_attr + ) x
tests/remove_cast_attr.res new file +10 -0
@@ -0,0 +1,10 @@ +#define __cast_attr MACROANNOTATION + +int func() +{ + int *a = (int) x; + int *a = (int) x; + int *a = (int *) x; + int *a = (int *) x; + int *a = (int) x; +}
Signature · 6 lines
2.21.1 _______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci
PATCH v2 32/32 tests: Add test case to detect cast attributes
In reply to Jaskaran SinghAdd a test case to detect a cast attribute. The following cases are covered for when a attribute is:
- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.
--- tests/detect_cast_attr.c | 10 ++++++++++ tests/detect_cast_attr.cocci | 11 +++++++++++ tests/detect_cast_attr.res | 10 ++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/detect_cast_attr.c create mode 100644 tests/detect_cast_attr.cocci create mode 100644 tests/detect_cast_attr.res
tests/detect_cast_attr.c new file +10 -0
@@ -0,0 +1,10 @@ +#define __cast_attr MACROANNOTATION + +int func () +{ + char *a = (int __cast_attr) x; + char *a = (__cast_attr int) x; + char *a = (int __cast_attr *) x; + char *a = (int *__cast_attr) x; +char *a = (int ) x; +}
tests/detect_cast_attr.cocci new file +11 -0
@@ -0,0 +1,11 @@ +@r0@ +type T; +attribute name __cast_attr; +identifier x; +@@ + + ( +- T ++ char * + __cast_attr + ) x
tests/detect_cast_attr.res new file +10 -0
@@ -0,0 +1,10 @@ +#define __cast_attr MACROANNOTATION + +int func() +{ + char *a = (char *__cast_attr) x; + char *a = (__cast_attr char *) x; + char *a = (char *__cast_attr) x; + char *a = (char *__cast_attr) x; + char *a = (int) x; +}
Signature · 6 lines
2.21.1 _______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci