[clang] Remove call to create_local_procdesc and create it only when it's called.

master
Dulma Rodriguez 10 years ago
parent 092e447ce3
commit b79028af32

@ -159,9 +159,7 @@ struct
CMethod_signature.add ms; CMethod_signature.add ms;
add_method tenv cg cfg curr_class procname namespace [body] is_objc_method is_instance add_method tenv cg cfg curr_class procname namespace [body] is_objc_method is_instance
captured_vars is_anonym_block fdecl_info.Clang_ast_t.fdi_parameters attributes captured_vars is_anonym_block fdecl_info.Clang_ast_t.fdi_parameters attributes
| None, ms -> | None, ms -> CMethod_signature.add ms
CMethod_trans.create_local_procdesc cfg tenv ms [] captured_vars false;
CMethod_signature.add ms
let process_objc_method_decl tenv cg cfg namespace curr_class decl_info method_name method_decl_info = let process_objc_method_decl tenv cg cfg namespace curr_class decl_info method_name method_decl_info =
let class_name = CContext.get_curr_class_name curr_class in let class_name = CContext.get_curr_class_name curr_class in

@ -300,7 +300,6 @@ struct
| Some v -> | Some v ->
CMethod_trans.mk_procname_from_function name v, CTypes_decl.parse_func_type name v CMethod_trans.mk_procname_from_function name v, CTypes_decl.parse_func_type name v
| None -> Procname.from_string name, None in | None -> Procname.from_string name, None in
CMethod_trans.create_external_procdesc context.cfg pname false type_opt;
let address_of_function = not context.CContext.is_callee_expression in 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.*) (* If we are not translating a callee expression, then the address of the function is being taken.*)
(* As e.g. in fun_ptr = foo; *) (* As e.g. in fun_ptr = foo; *)
@ -528,39 +527,20 @@ struct
let (sil_fe, typ_fe) = extract_exp_from_list res_trans_callee.exps let (sil_fe, typ_fe) = extract_exp_from_list res_trans_callee.exps
"WARNING: The translation of fun_exp did not return an expression. Returning -1. NEED TO BE FIXED" in "WARNING: The translation of fun_exp did not return an expression. Returning -1. NEED TO BE FIXED" in
let callee_pname_opt = let callee_pname_opt =
match sil_fe with match sil_fe with
| Sil.Const (Sil.Cfun pn) -> | Sil.Const (Sil.Cfun pn) ->
Some pn Some pn
| _ -> None (* function pointer *) in | _ -> None (* function pointer *) in
let should_translate_args = let should_translate_args =
match callee_pname_opt with match callee_pname_opt with
| Some pn -> | Some pn ->
(* we cannot translate the arguments of this builtin because preprocessing copies them *) (* we cannot translate the arguments of this builtin because preprocessing copies them *)
(* verbatim from a call to a different function, and they might be side-effecting *) (* verbatim from a call to a different function, and they might be side-effecting *)
(Procname.to_string pn) <> CFrontend_config.builtin_object_size (Procname.to_string pn) <> CFrontend_config.builtin_object_size
| _ -> true in | _ -> true in
let params_stmt = if should_translate_args then
let assign_default_params params_stmt = CTrans_utils.assign_default_params params_stmt callee_pname_opt
match callee_pname_opt with else [] in
| None -> params_stmt
| Some callee_pname ->
try
let callee_ms = CMethod_signature.find callee_pname in
let args = CMethod_signature.ms_get_args callee_ms in
let params_args = list_combine params_stmt args in
let replace_default_arg param =
match param with
| CXXDefaultArgExpr(_, _, _), (_, _, Some default_instr) -> default_instr
| instr, _ -> instr in
list_map replace_default_arg params_args
with
| Invalid_argument _ ->
(* list_combine failed because of different list lengths *)
Printing.log_err "Param count doesn't match %s\n" (Procname.to_string callee_pname);
params_stmt
| Not_found -> params_stmt in
let params_stmt = if should_translate_args then assign_default_params params_stmt else [] in
let res_trans_par = let res_trans_par =
let l = list_map (fun i -> exec_with_self_exception instruction trans_state_param i) params_stmt in let l = list_map (fun i -> exec_with_self_exception instruction trans_state_param i) params_stmt in
let rt = collect_res_trans (res_trans_callee :: l) in let rt = collect_res_trans (res_trans_callee :: l) in

@ -659,3 +659,23 @@ let is_dispatch_function stmt_list =
) )
| _ -> None)) | _ -> None))
| _ -> None | _ -> None
let assign_default_params params_stmt callee_pname_opt =
match callee_pname_opt with
| None -> params_stmt
| Some callee_pname ->
try
let callee_ms = CMethod_signature.find callee_pname in
let args = CMethod_signature.ms_get_args callee_ms in
let params_args = list_combine params_stmt args in
let replace_default_arg param =
match param with
| CXXDefaultArgExpr(_, _, _), (_, _, Some default_instr) -> default_instr
| instr, _ -> instr in
list_map replace_default_arg params_args
with
| Invalid_argument _ ->
(* list_combine failed because of different list lengths *)
Printing.log_err "Param count doesn't match %s\n" (Procname.to_string callee_pname);
params_stmt
| Not_found -> params_stmt

@ -196,3 +196,5 @@ val compute_autorelease_pool_vars : CContext.t -> Clang_ast_t.stmt list -> (Sil.
val is_logical_negation_of_int : Sil.tenv -> Clang_ast_t.expr_info -> Clang_ast_t.unary_operator_info -> bool val is_logical_negation_of_int : Sil.tenv -> Clang_ast_t.expr_info -> Clang_ast_t.unary_operator_info -> bool
val is_dispatch_function : Clang_ast_t.stmt list -> int option val is_dispatch_function : Clang_ast_t.stmt list -> int option
val assign_default_params : Clang_ast_t.stmt list -> Procname.t option -> Clang_ast_t.stmt list

Loading…
Cancel
Save