diff --git a/infer/src/backend/cfg.ml b/infer/src/backend/cfg.ml index beb37e94f..aa4851634 100644 --- a/infer/src/backend/cfg.ml +++ b/infer/src/backend/cfg.ml @@ -373,6 +373,20 @@ module Node = struct (** Counter for identifiers of procdescs *) let proc_desc_id_counter = ref 0 + let proc_desc_create cfg proc_attributes = + incr proc_desc_id_counter; + let pdesc = + { + pd_attributes = proc_attributes; + pd_id = !proc_desc_id_counter; + pd_nodes = []; + pd_start_node = dummy (); + pd_exit_node = dummy (); + pd_changed = true + } in + pdesc_tbl_add cfg proc_attributes.ProcAttributes.proc_name pdesc; + pdesc + let remove_node' filter_out_fun cfg node = let remove_node_in_cfg nodes = IList.filter filter_out_fun nodes in @@ -620,26 +634,7 @@ module Procdesc = struct type t = Node.proc_desc let compute_distance_to_exit_node = Node.proc_desc_compute_distance_to_exit_node - type proc_desc_builder = - { cfg : cfg; - proc_attributes : ProcAttributes.t; - } - - let create (b : proc_desc_builder) = - let open Node in - incr proc_desc_id_counter; - let pdesc = - { - pd_attributes = b.proc_attributes; - pd_id = !proc_desc_id_counter; - pd_nodes = []; - pd_start_node = dummy (); - pd_exit_node = dummy (); - pd_changed = true - } in - pdesc_tbl_add b.cfg b.proc_attributes.ProcAttributes.proc_name pdesc; - pdesc - + let create = Node.proc_desc_create let remove = Node.proc_desc_remove let find_from_name = Node.proc_desc_from_name let get_attributes = Node.proc_desc_get_attributes diff --git a/infer/src/backend/cfg.mli b/infer/src/backend/cfg.mli index ec39e94c8..7c9e23217 100644 --- a/infer/src/backend/cfg.mli +++ b/infer/src/backend/cfg.mli @@ -31,13 +31,8 @@ module Procdesc : sig (** Compute the distance of each node to the exit node, if not computed already *) val compute_distance_to_exit_node : t -> unit - type proc_desc_builder = - { cfg : cfg; - proc_attributes : ProcAttributes.t; - } - (** Create a procdesc *) - val create : proc_desc_builder -> t + val create : cfg -> ProcAttributes.t -> t (** [remove cfg name remove_nodes] remove the procdesc [name] from the control flow graph [cfg]. *) (** It also removes all the nodes from the procedure from the cfg if remove_nodes is true *) diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index 0ef226817..b4b2d9edc 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -580,15 +580,15 @@ let check_deallocate_static_memory prop_after = let proc_desc_copy cfg pdesc pname pname' = if (Procname.equal pname pname') then pdesc else - (match Cfg.Procdesc.find_from_name cfg pname' with - | Some pdesc' -> pdesc' - | None -> - Cfg.Procdesc.create { - Cfg.Procdesc.cfg = cfg; - proc_attributes = - { (ProcAttributes.copy (Cfg.Procdesc.get_attributes pdesc)) with - ProcAttributes.proc_name = pname'; }; - }) + begin + match Cfg.Procdesc.find_from_name cfg pname' with + | Some pdesc' -> pdesc' + | None -> + let proc_attributes = + { (ProcAttributes.copy (Cfg.Procdesc.get_attributes pdesc)) with + ProcAttributes.proc_name = pname'; } in + Cfg.Procdesc.create cfg proc_attributes + end let method_exists right_proc_name methods = if !Config.curr_language = Config.Java then diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 7de6b0de9..baf968497 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -349,10 +349,7 @@ let create_local_procdesc cfg tenv ms fbody captured is_objc_inst_method = method_annotation; ret_type; } in - Cfg.Procdesc.create { - Cfg.Procdesc.cfg; - proc_attributes; - } in + Cfg.Procdesc.create cfg proc_attributes in if defined then (if !Config.arc_mode then Cfg.Procdesc.set_flag procdesc Mleak_buckets.objc_arc_flag "true"; @@ -377,19 +374,14 @@ let create_external_procdesc cfg proc_name is_objc_inst_method type_opt = ret_type, IList.map (fun typ -> (Mangled.from_string "x", typ)) arg_types | None -> Sil.Tvoid, []) in let loc = Location.dummy in - let _ = - let proc_attributes = - { (ProcAttributes.default proc_name Config.C_CPP) with - ProcAttributes.formals; - is_objc_instance_method = is_objc_inst_method; - loc; - ret_type; - } in - Cfg.Procdesc.create { - Cfg.Procdesc.cfg = cfg; - proc_attributes = proc_attributes; + let proc_attributes = + { (ProcAttributes.default proc_name Config.C_CPP) with + ProcAttributes.formals; + is_objc_instance_method = is_objc_inst_method; + loc; + ret_type; } in - () + ignore (Cfg.Procdesc.create cfg proc_attributes) let create_procdesc_with_pointer context pointer class_name_opt name tp = let open CContext in diff --git a/infer/src/harness/inhabit.ml b/infer/src/harness/inhabit.ml index db8868cbf..dd62ce96c 100644 --- a/infer/src/harness/inhabit.ml +++ b/infer/src/harness/inhabit.ml @@ -270,10 +270,7 @@ let setup_harness_cfg harness_name harness_cfg env source_dir cg tenv = ProcAttributes.is_defined = true; loc = env.pc; } in - Cfg.Procdesc.create { - Cfg.Procdesc.cfg = harness_cfg; - proc_attributes; - } in + Cfg.Procdesc.create harness_cfg proc_attributes in let harness_node = (* important to reverse the list or there will be scoping issues! *) let instrs = (IList.rev env.instrs) in diff --git a/infer/src/java/jTrans.ml b/infer/src/java/jTrans.ml index f7a23bdbc..7493ca096 100644 --- a/infer/src/java/jTrans.ml +++ b/infer/src/java/jTrans.ml @@ -297,10 +297,7 @@ let create_local_procdesc program linereader cfg tenv node m = method_annotation; ret_type = JTransType.return_type program tenv ms meth_kind; } in - Cfg.Procdesc.create { - Cfg.Procdesc.cfg = cfg; - proc_attributes; - } in + Cfg.Procdesc.create cfg proc_attributes in let start_kind = Cfg.Node.Start_node procdesc in let start_node = Cfg.Node.create cfg Location.dummy start_kind [] procdesc [] in let exit_kind = (Cfg.Node.Exit_node procdesc) in @@ -311,22 +308,17 @@ let create_local_procdesc program linereader cfg tenv node m = | Javalib.ConcreteMethod cm when is_java_native cm -> let formals = formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in - let _procdesc = - let proc_attributes = - { (ProcAttributes.default proc_name Config.Java) with - ProcAttributes.access = trans_access cm.Javalib.cm_access; - exceptions = IList.map JBasics.cn_name cm.Javalib.cm_exceptions; - formals; - is_bridge_method = cm.Javalib.cm_bridge; - is_synthetic_method = cm.Javalib.cm_synthetic; - method_annotation; - ret_type = JTransType.return_type program tenv ms meth_kind; - } in - Cfg.Procdesc.create { - Cfg.Procdesc.cfg = cfg; - proc_attributes = proc_attributes; + let proc_attributes = + { (ProcAttributes.default proc_name Config.Java) with + ProcAttributes.access = trans_access cm.Javalib.cm_access; + exceptions = IList.map JBasics.cn_name cm.Javalib.cm_exceptions; + formals; + is_bridge_method = cm.Javalib.cm_bridge; + is_synthetic_method = cm.Javalib.cm_synthetic; + method_annotation; + ret_type = JTransType.return_type program tenv ms meth_kind; } in - () + ignore (Cfg.Procdesc.create cfg proc_attributes) | Javalib.ConcreteMethod cm -> let impl = get_implementation cm in let locals, formals = locals_formals program tenv cn impl meth_kind in @@ -351,10 +343,7 @@ let create_local_procdesc program linereader cfg tenv node m = method_annotation; ret_type = JTransType.return_type program tenv ms meth_kind; } in - Cfg.Procdesc.create { - Cfg.Procdesc.cfg = cfg; - proc_attributes = proc_attributes; - } in + Cfg.Procdesc.create cfg proc_attributes in let start_kind = Cfg.Node.Start_node procdesc in let start_node = Cfg.Node.create cfg loc_start start_kind [] procdesc [] in let exit_kind = (Cfg.Node.Exit_node procdesc) in @@ -391,10 +380,7 @@ let create_external_procdesc program cfg tenv cn ms kind = ProcAttributes.formals; ret_type = return_type; } in - Cfg.Procdesc.create { - Cfg.Procdesc.cfg = cfg; - proc_attributes = proc_attributes; - }) + Cfg.Procdesc.create cfg proc_attributes) (** returns the procedure description of the given method and creates it if it hasn't been created before *) let rec get_method_procdesc program cfg tenv cn ms kind =