diff --git a/install.txt b/install.txt index 8933f8081fcfc84e952f976310f9a0df7085600c..12fa9879cb25a8f6687f6b74d0a543983d8ff069 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: @@ -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. diff --git a/parsing_c/control_flow_c_build.ml b/parsing_c/control_flow_c_build.ml index b500ed00bab9239817f9e8250a06fcd4a6a3bf76..19254ec9af21b3074a9ad272aa79b1a8961a3134 100644 --- a/parsing_c/control_flow_c_build.ml +++ b/parsing_c/control_flow_c_build.ml @@ -1562,8 +1562,15 @@ 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 - raise (Error (DeadCode (Some (pinfo_of_ii ii)))) + let ii = Ast_c.get_ii_st_take_care st in + 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" ) ) diff --git a/parsing_c/lexer_c.mll b/parsing_c/lexer_c.mll index 9ac5821041d5dab0bb5a175d844c77ae219044ef..bcdc1945cbd4030602f13c876af93a7cf43c77e9 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 10cd443576e5b7976f06b5d0d4e7a6bdd0bbf6e4..a04d73594bfd64f77e220271339963b0c400d486 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 d604fd6364376c216243f7c2df86389e26bf12db..5c9897c6ce6f0dadf194a79ba4f7ffa259b47ca0 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 9fa4e45a223ce6ae989438eef55ff2fc908ac9fa..ed911fddcd4d034cbfd7e9554f0ef98f43985c04 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 592c7cb9d35732e46538ed38b9ae93f32e18c0bd..f0025cdd79356eff7b1158b0a1122336670346f8 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; @@ -367,6 +371,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; @@ -523,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 -> @@ -531,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 -> @@ -555,6 +568,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; diff --git a/tests/rb.c b/tests/rb.c new file mode 100644 index 0000000000000000000000000000000000000000..fd5e5a93923803b5ca52036b69e178e34d85bb8c --- /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 0000000000000000000000000000000000000000..a9bd6854779b88dac36372effdbaf3a7bb7baff3 --- /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 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/tests/rb.res @@ -0,0 +1 @@ +