From e5f6df74b06bc7ef5ed3075aab819c773ec4a60a Mon Sep 17 00:00:00 2001 From: Dulma Rodriguez Date: Thu, 20 Aug 2015 10:03:11 -0100 Subject: [PATCH] [clang] Add procdescs to cxx method. Forgotten from last commit --- infer/src/clang/cMethod_trans.ml | 13 +++++++++++++ infer/src/clang/cMethod_trans.mli | 2 ++ infer/src/clang/cTrans.ml | 13 ++++++------- infer/src/clang/cTrans_utils.mli | 2 ++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 7bf9c3a03..03d7f2ffe 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -336,6 +336,19 @@ let create_external_procdesc cfg procname is_objc_inst_method type_opt = } in () +let create_procdesc_with_pointer context pointer_opt callee_name = + let open CContext in + let callee_ms_opt = + match pointer_opt with + | Some pointer -> + (match method_signature_of_pointer None pointer with + | Some callee_ms -> Some callee_ms + | None -> None) + | None -> None in + match callee_ms_opt with + | Some callee_ms -> ignore (create_local_procdesc context.cfg context.tenv callee_ms [] [] false) + | None -> create_external_procdesc context.cfg callee_name false None + let instance_to_method_call_type instance = if instance then MCVirtual else MCStatic diff --git a/infer/src/clang/cMethod_trans.mli b/infer/src/clang/cMethod_trans.mli index 44228b2e7..ab035aead 100644 --- a/infer/src/clang/cMethod_trans.mli +++ b/infer/src/clang/cMethod_trans.mli @@ -36,3 +36,5 @@ val method_signature_of_decl : string option -> Clang_ast_t.decl -> CModule_type CMethod_signature.method_signature * Clang_ast_t.stmt option * Clang_ast_t.decl list val method_signature_of_pointer : string option -> Clang_ast_t.pointer -> CMethod_signature.method_signature option + +val create_procdesc_with_pointer : CContext.t -> Clang_ast_t.pointer option -> Procname.t -> unit diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 91af7978a..b2edbfabc 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -325,11 +325,7 @@ struct | Some v -> (General_utils.mk_procname_from_function name v, CTypes_decl.parse_func_type name v) | None -> (Procname.from_string_c_fun name, None) in - (match CMethod_trans.method_signature_of_pointer None pointer with - | Some callee_ms -> - ignore (CMethod_trans.create_local_procdesc context.cfg context.tenv callee_ms [] [] false) - | None -> - CMethod_trans.create_external_procdesc context.cfg pname false None); + CMethod_trans.create_procdesc_with_pointer context (Some pointer) pname; let address_of_function = not context.CContext.is_callee_expression in (* If we are not translating a callee expression, then the address of the function is being taken.*) (* As e.g. in fun_ptr = foo; *) @@ -620,10 +616,11 @@ struct | _ -> assert false) (* by construction of red_id, we cannot be in this case *) and cxxMemberCallExpr_trans trans_state si stmt_list expr_info = + let open CContext in let pln = trans_state.parent_line_number in let context = trans_state.context in - let function_type = CTypes_decl.get_type_from_expr_info expr_info context.CContext.tenv in - let procname = Cfg.Procdesc.get_proc_name context.CContext.procdesc in + let function_type = CTypes_decl.get_type_from_expr_info expr_info context.tenv in + let procname = Cfg.Procdesc.get_proc_name context.procdesc in let sil_loc = CLocation.get_sil_location si pln context in (* First stmt is the method+this expr and the rest are params *) let fun_exp_stmt, params_stmt = (match stmt_list with @@ -644,6 +641,8 @@ struct | Sil.Const (Sil.Cfun pn) -> pn | _ -> assert false (* method pointer not implemented, this shouldn't happen *) in let class_name_opt = Some (Procname.c_get_class callee_pname) in + let pointer_opt = CTrans_utils.pointer_of_call_expr fun_exp_stmt in + CMethod_trans.create_procdesc_with_pointer context pointer_opt callee_pname; let params_stmt = CTrans_utils.assign_default_params params_stmt class_name_opt fun_exp_stmt ~is_cxx_method:true in (* As we may have nodes coming from different parameters we need to *) (* call instruction for each parameter and collect the results *) diff --git a/infer/src/clang/cTrans_utils.mli b/infer/src/clang/cTrans_utils.mli index 5a8b37651..6c62a875e 100644 --- a/infer/src/clang/cTrans_utils.mli +++ b/infer/src/clang/cTrans_utils.mli @@ -209,3 +209,5 @@ val assign_default_params : Clang_ast_t.stmt list -> string option -> Clang_ast_ is_cxx_method:bool -> Clang_ast_t.stmt list val is_block_enumerate_function : Clang_ast_t.obj_c_message_expr_info -> bool + +val pointer_of_call_expr : Clang_ast_t.stmt -> Clang_ast_t.pointer option