From 84a1a4d528d70dc15292d52cf5ff1fa367386dad Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sun, 8 Mar 2020 15:38:49 +0100 Subject: [PATCH 1/7] fail more gracefully on dead code Due to macros, there may be some fake nodes, and thus no position information. Just print some information that is not totally useless to find the problem. Problem noted by Markus Elfring --- parsing_c/control_flow_c_build.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/parsing_c/control_flow_c_build.ml b/parsing_c/control_flow_c_build.ml index b500ed00..0487a6e0 100644 --- a/parsing_c/control_flow_c_build.ml +++ b/parsing_c/control_flow_c_build.ml @@ -1563,7 +1563,14 @@ let deadcode_detection (g : Control_flow_c.cflow) = (match Control_flow_c.extract_fullstatement node with | Some st -> let ii = Ast_c.get_ii_st_take_care st in - raise (Error (DeadCode (Some (pinfo_of_ii ii)))) + let loc = + try Some (pinfo_of_ii ii) + with _ -> + begin + Printf.eprintf "dead code problem in: %s\n" (Dumper.dump st); + None + end in + raise (Error (DeadCode loc)) | _ -> pr2 "CFG: orphan nodes, maybe something weird happened" ) ) -- GitLab From 3b38f9950e650c417bb062ff102d214d43e0687a Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sun, 8 Mar 2020 15:39:07 +0100 Subject: [PATCH 2/7] spaces -> tab --- parsing_c/control_flow_c_build.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parsing_c/control_flow_c_build.ml b/parsing_c/control_flow_c_build.ml index 0487a6e0..19254ec9 100644 --- a/parsing_c/control_flow_c_build.ml +++ b/parsing_c/control_flow_c_build.ml @@ -1562,7 +1562,7 @@ let deadcode_detection (g : Control_flow_c.cflow) = | x -> (match Control_flow_c.extract_fullstatement node with | Some st -> - let ii = Ast_c.get_ii_st_take_care st in + let ii = Ast_c.get_ii_st_take_care st in let loc = try Some (pinfo_of_ii ii) with _ -> -- GitLab From c11db354b964f9aec8ff0fd66bbc8d81b4aa0d4a Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sun, 29 Mar 2020 18:07:57 +0200 Subject: [PATCH 3/7] clear attr names like the rest --- parsing_cocci/lexer_cocci.mll | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parsing_cocci/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll index 592c7cb9..f05c6de0 100644 --- a/parsing_cocci/lexer_cocci.mll +++ b/parsing_cocci/lexer_cocci.mll @@ -367,6 +367,7 @@ let init _ = (* per file, first .cocci then iso *) Hashtbl.clear Data.all_metadecls; Hashtbl.clear metavariables; Hashtbl.clear type_names; + Hashtbl.clear attr_names; Hashtbl.clear rule_names; Hashtbl.clear iterator_names; Hashtbl.clear declarer_names; @@ -555,6 +556,7 @@ let post_init _ = Stdcompat.Hashtbl.reset Data.all_metadecls; Stdcompat.Hashtbl.reset metavariables; Stdcompat.Hashtbl.reset type_names; + Stdcompat.Hashtbl.reset attr_names; Stdcompat.Hashtbl.reset rule_names; Stdcompat.Hashtbl.reset iterator_names; Stdcompat.Hashtbl.reset declarer_names; -- GitLab From b8b5e86156804212d776f89610ba2f555fe8fb2e Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sun, 29 Mar 2020 19:21:08 +0200 Subject: [PATCH 4/7] make information about SmPL iterator and declarer names available to the C parser --- tests/rb.c | 2 ++ tests/rb.cocci | 5 +++++ tests/rb.res | 1 + 3 files changed, 8 insertions(+) create mode 100644 tests/rb.c create mode 100644 tests/rb.cocci create mode 100644 tests/rb.res diff --git a/tests/rb.c b/tests/rb.c new file mode 100644 index 00000000..fd5e5a93 --- /dev/null +++ b/tests/rb.c @@ -0,0 +1,2 @@ +RB_DECLARE_CALLBACKS_MAX(static, augment_callbacks, struct drbd_interval, +rb, sector_t, end, NODE_END); diff --git a/tests/rb.cocci b/tests/rb.cocci new file mode 100644 index 00000000..a9bd6854 --- /dev/null +++ b/tests/rb.cocci @@ -0,0 +1,5 @@ +@@ +declarer name RB_DECLARE_CALLBACKS_MAX; +@@ + +- RB_DECLARE_CALLBACKS_MAX(..., NODE_END); \ No newline at end of file diff --git a/tests/rb.res b/tests/rb.res new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/tests/rb.res @@ -0,0 +1 @@ + -- GitLab From d7f1dfbba43a8300a4e851341d4677db76edb8f1 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Mon, 30 Mar 2020 22:10:04 +0200 Subject: [PATCH 5/7] make information about SmPL iterator and declarer names available to the C parser --- parsing_c/lexer_c.mll | 15 +++++++++++- parsing_c/parser_c.mly | 46 ++++++++++++++++++++++++++++++++--- parsing_cocci/data.ml | 8 ++++++ parsing_cocci/data.mli | 8 ++++++ parsing_cocci/lexer_cocci.mll | 14 ++++++++++- 5 files changed, 86 insertions(+), 5 deletions(-) diff --git a/parsing_c/lexer_c.mll b/parsing_c/lexer_c.mll index 9ac58210..bcdc1945 100644 --- a/parsing_c/lexer_c.mll +++ b/parsing_c/lexer_c.mll @@ -860,7 +860,20 @@ rule token = parse * now done in parse_c.ml. *) - | None -> TIdent (s, info) + | None -> + (* get information from the semantic patch *) + (* typedef is not done due to tyex.cocci *) + (* attributes not done due to roa; don't know + whether to use MacroAttr or MacroEndAttr *) + (*if List.mem s !Data.type_names + then TypedefIdent (s, info) + else if List.mem s !Data.attr_names + then TMacroAttr (s, info) + else*) if List.mem s !Data.declarer_names + then TMacroDecl (s, info) + else if List.mem s !Data.iterator_names + then TMacroIterator (s, info) + else TIdent (s, info) ) } (* gccext: apparently gcc allows dollar in variable names. found such diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 10cd4435..a04d7359 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -211,6 +211,13 @@ let fixDeclSpecForParam = function ({storageD = (st,iist)} as r) -> (Semantic ("storage class specified for parameter of function", fake_pi)) +let fixDeclSpecForArg = function ({storageD = (st,iist)} as r) -> + let ((qu,ty) as v,_st) = fixDeclSpecForDecl r in + match st with + | (Sto Register) -> (v, true), iist + | (Sto _) -> (v, false), iist + | NoSto | StoTypedef -> (v, false), iist + let fixDeclSpecForMacro = function ({storageD = (st,iist)} as r) -> let ((qu,ty) as v,_st) = fixDeclSpecForDecl r in match st with @@ -950,13 +957,13 @@ string_format: /*(* to avoid conflicts have to introduce a _not_empty (ne) version *)*/ argument_ne: | assign_expr { Left $1 } - | parameter_decl { Right (ArgType $1) } + | parameter_decl_arg { Right (ArgType $1) } | action_higherordermacro_ne { Right (ArgAction $1) } argument: | assign_expr { Left $1 } - | parameter_decl { Right (ArgType $1) } + | parameter_decl_arg { Right (ArgType $1) } /*(* had conflicts before, but julia fixed them *)*/ | action_higherordermacro { Right (ArgAction $1) } @@ -1481,8 +1488,41 @@ parameter_decl2: } } | decl_spec + { let ((returnType,hasreg), iihasreg) = fixDeclSpecForParam (snd $1) in + { p_namei = None; + p_type = returnType; + p_register = hasreg, iihasreg; + } + } + +parameter_decl_arg: /* more tolerant */ + TKRParam { + let name = RegularName (mk_string_wrap $1) in + LP.add_ident (str_of_name name); + { p_namei = Some name; + p_type = mk_ty NoType []; + p_register = (false, []); + } + } + | decl_spec declaratorp { LP.kr_impossible(); - let ((returnType,hasreg), iihasreg) = fixDeclSpecForParam (snd $1) in + let ((returnType,hasreg),iihasreg) = fixDeclSpecForArg (snd $1) in + let (name, ftyp) = $2 in + { p_namei = Some (name); + p_type = ftyp returnType; + p_register = (hasreg, iihasreg); + } + } + | decl_spec abstract_declaratorp + { LP.kr_impossible(); + let ((returnType,hasreg), iihasreg) = fixDeclSpecForArg (snd $1) in + { p_namei = None; + p_type = $2 returnType; + p_register = hasreg, iihasreg; + } + } + | decl_spec + { let ((returnType,hasreg), iihasreg) = fixDeclSpecForArg (snd $1) in { p_namei = None; p_type = returnType; p_register = hasreg, iihasreg; diff --git a/parsing_cocci/data.ml b/parsing_cocci/data.ml index d604fd63..5c9897c6 100644 --- a/parsing_cocci/data.ml +++ b/parsing_cocci/data.ml @@ -160,3 +160,11 @@ let non_local_script_constraints = let fresh_id_scripts: (Ast_cocci.meta_name * Ast_cocci.seed_script) list ref = ref [] + +(* ---------------------------------------------------------------------- *) +(* Names of some special tokens. Make these acessible to the C parser *) + +let type_names = ref ([]:string list) +let attr_names = ref ([]:string list) +let declarer_names = ref ([]:string list) +let iterator_names = ref ([]:string list) diff --git a/parsing_cocci/data.mli b/parsing_cocci/data.mli index 9fa4e45a..ed911fdd 100644 --- a/parsing_cocci/data.mli +++ b/parsing_cocci/data.mli @@ -138,3 +138,11 @@ val non_local_script_constraints: val fresh_id_scripts: (Ast_cocci.meta_name * Ast_cocci.seed_script) list ref (** The list of all fresh id scripts. *) + +(* ---------------------------------------------------------------------- *) +(* Names of some special tokens. Make these acessible to the C parser *) + +val type_names : string list ref +val attr_names : string list ref +val declarer_names : string list ref +val iterator_names : string list ref diff --git a/parsing_cocci/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll index f05c6de0..f0025cdd 100644 --- a/parsing_cocci/lexer_cocci.mll +++ b/parsing_cocci/lexer_cocci.mll @@ -347,7 +347,11 @@ let mkassign op lexbuf = TOpAssign (op, (get_current_line_type lexbuf)) let spinit _ = (* per semantic patch *) - Hashtbl.clear Data.non_local_script_constraints + Hashtbl.clear Data.non_local_script_constraints; + D.type_names := []; + D.attr_names := []; + D.iterator_names := []; + D.declarer_names := [] let init _ = (* per file, first .cocci then iso *) line := 1; @@ -524,6 +528,8 @@ let init _ = (* per file, first .cocci then iso *) Data.add_type_name := (function name -> let fn clt = TTypeId(name,clt) in + (if not (List.mem name !D.type_names) + then D.type_names := name :: !D.type_names); Hashtbl.replace type_names name fn); Data.add_attribute := (function name -> @@ -532,14 +538,20 @@ let init _ = (* per file, first .cocci then iso *) ((Data.PLUS | Data.PLUSPLUS),_,_,_,_,_,_,_,_,_) -> TDirective (Ast.Space name, clt) | _ -> Tattr (name, clt) in + (if not (List.mem name !D.attr_names) + then D.attr_names := name :: !D.attr_names); Hashtbl.replace attr_names name fn); Data.add_declarer_name := (function name -> let fn clt = TDeclarerId(name,clt) in + (if not (List.mem name !D.declarer_names) + then D.declarer_names := name :: !D.declarer_names); Hashtbl.replace declarer_names name fn); Data.add_iterator_name := (function name -> let fn clt = TIteratorId(name,clt) in + (if not (List.mem name !D.iterator_names) + then D.iterator_names := name :: !D.iterator_names); Hashtbl.replace iterator_names name fn); Data.add_symbol_meta := (function name -> -- GitLab From c83fa2ef72ce35c9e2c98399cf681af8207aaa24 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Tue, 16 Jun 2020 11:40:59 +0200 Subject: [PATCH 6/7] make need fo sudo apparent --- install.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.txt b/install.txt index 8933f808..ac605190 100644 --- a/install.txt +++ b/install.txt @@ -45,7 +45,7 @@ Then simply type ./autogen ./configure make - make install + sudo make install Other configuration flags of interest: -- GitLab From 20fea9180a6adfdbcc5023985d7ea57e00d2e75c Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Tue, 16 Jun 2020 11:41:18 +0200 Subject: [PATCH 7/7] spatch is no longer a script --- install.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install.txt b/install.txt index ac605190..12fa9879 100644 --- a/install.txt +++ b/install.txt @@ -67,8 +67,7 @@ defaults to the optimized version, unless --disable-opt is given to configure. You could use 'make opt-only' to compile the optimized version only. Similarly, you can use 'make byte-only' for the unoptimized version. 'make install' installs whichever version -was compiled, and installs a script 'spatch' (the frontend) that invokes -the 'best' one with proper environment variables. +was compiled. You can also use 'make world' to compile the bytecode and the optimized code version. -- GitLab