killing a bunch of options by using optional argument types correctly

Reviewed By: cristianoc

Differential Revision: D3778667

fbshipit-source-id: ce1f173
master
Sam Blackshear 8 years ago committed by Facebook Github Bot 6
parent 80c82c0cae
commit 15b6a8cdd7

@ -458,7 +458,7 @@ let check_assignement_guard node =
let desc = Errdesc.explain_condition_is_assignment l_node in let desc = Errdesc.explain_condition_is_assignment l_node in
let exn = Exceptions.Condition_is_assignment (desc, __POS__) in let exn = Exceptions.Condition_is_assignment (desc, __POS__) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_warning pname ~loc: (Some l_node) ~pre: pre_opt exn Reporting.log_warning pname ~loc:l_node ?pre:pre_opt exn
) )
else () else ()
| _ -> | _ ->
@ -508,7 +508,7 @@ let forward_tabulate tenv wl =
| None -> ()); | None -> ());
L.d_strln "SIL INSTR:"; L.d_strln "SIL INSTR:";
Cfg.Node.d_instrs ~sub_instrs: true (State.get_instr ()) curr_node; L.d_ln (); Cfg.Node.d_instrs ~sub_instrs: true (State.get_instr ()) curr_node; L.d_ln ();
Reporting.log_error ~pre: pre_opt curr_pname exn; Reporting.log_error ?pre:pre_opt curr_pname exn;
State.mark_instr_fail pre_opt exn; State.mark_instr_fail pre_opt exn;
handled_some_exception := true in handled_some_exception := true in
@ -1044,7 +1044,7 @@ let perform_analysis_phase tenv (pname : Procname.t) (pdesc : Cfg.Procdesc.t)
Exceptions.Internal_error Exceptions.Internal_error
(Localise.verbatim_desc "Leak_while_collecting_specs_after_footprint") in (Localise.verbatim_desc "Leak_while_collecting_specs_after_footprint") in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_error pname ~pre: pre_opt exn; Reporting.log_error pname ?pre:pre_opt exn;
[] (* retuning no specs *) in [] (* retuning no specs *) in
specs, Specs.FOOTPRINT in specs, Specs.FOOTPRINT in
let wl = path_set_create_worklist pdesc in let wl = path_set_create_worklist pdesc in
@ -1204,7 +1204,7 @@ let report_runtime_exceptions tenv pdesc summary =
pp_to_string (Prop.pp_prop pe_text) (Specs.Jprop.to_prop pre) in pp_to_string (Prop.pp_prop pe_text) (Specs.Jprop.to_prop pre) in
let exn_desc = Localise.java_unchecked_exn_desc pname runtime_exception pre_str in let exn_desc = Localise.java_unchecked_exn_desc pname runtime_exception pre_str in
let exn = Exceptions.Java_runtime_exception (runtime_exception, pre_str, exn_desc) in let exn = Exceptions.Java_runtime_exception (runtime_exception, pre_str, exn_desc) in
Reporting.log_error pname ~pre: (Some (Specs.Jprop.to_prop pre)) exn in Reporting.log_error pname ~pre:(Specs.Jprop.to_prop pre) exn in
IList.iter report exn_preconditions IList.iter report exn_preconditions
@ -1217,7 +1217,7 @@ let report_custom_errors summary =
let loc = summary.Specs.attributes.ProcAttributes.loc in let loc = summary.Specs.attributes.ProcAttributes.loc in
let err_desc = Localise.desc_custom_error loc in let err_desc = Localise.desc_custom_error loc in
let exn = Exceptions.Custom_error (custom_error, err_desc) in let exn = Exceptions.Custom_error (custom_error, err_desc) in
Reporting.log_error pname ~pre: (Some (Specs.Jprop.to_prop pre)) exn in Reporting.log_error pname ~pre:(Specs.Jprop.to_prop pre) exn in
IList.iter report error_preconditions IList.iter report error_preconditions
module SpecMap = Map.Make (struct module SpecMap = Map.Make (struct

@ -63,7 +63,7 @@ let check_bad_index pname p len index loc =
Exceptions.Array_out_of_bounds_l1 Exceptions.Array_out_of_bounds_l1
(Errdesc.explain_array_access deref_str p loc, __POS__) in (Errdesc.explain_array_access deref_str p loc, __POS__) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_warning pname ~pre: pre_opt exn Reporting.log_warning pname ?pre:pre_opt exn
else if len_is_constant then else if len_is_constant then
let deref_str = Localise.deref_str_array_bound len_const_opt index_const_opt in let deref_str = Localise.deref_str_array_bound len_const_opt index_const_opt in
let desc = Errdesc.explain_array_access deref_str p loc in let desc = Errdesc.explain_array_access deref_str p loc in
@ -71,7 +71,7 @@ let check_bad_index pname p len index loc =
then Exceptions.Array_out_of_bounds_l2 (desc, __POS__) then Exceptions.Array_out_of_bounds_l2 (desc, __POS__)
else Exceptions.Array_out_of_bounds_l3 (desc, __POS__) in else Exceptions.Array_out_of_bounds_l3 (desc, __POS__) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_warning pname ~pre: pre_opt exn Reporting.log_warning pname ?pre:pre_opt exn
end end
(** Perform bounds checking *) (** Perform bounds checking *)
@ -1058,7 +1058,7 @@ let check_type_size pname prop texp off typ_from_instr =
Exceptions.Pointer_size_mismatch ( Exceptions.Pointer_size_mismatch (
Errdesc.explain_dereference deref_str prop loc, __POS__) in Errdesc.explain_dereference deref_str prop loc, __POS__) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_warning pname ~pre: pre_opt exn Reporting.log_warning pname ?pre:pre_opt exn
end end
| None -> | None ->
L.d_str "texp: "; Sil.d_texp_full texp; L.d_ln () L.d_str "texp: "; Sil.d_texp_full texp; L.d_ln ()

@ -12,11 +12,11 @@ open! Utils
module L = Logging module L = Logging
type log_t = type log_t =
?loc: Location.t option -> ?loc: Location.t ->
?node_id: (int * int) option -> ?node_id: (int * int) ->
?session: int option -> ?session: int ->
?ltr: Errlog.loc_trace option -> ?ltr: Errlog.loc_trace ->
?pre: Prop.normal Prop.t option -> ?pre: Prop.normal Prop.t ->
exn -> exn ->
unit unit
@ -24,15 +24,7 @@ type log_issue = Procname.t -> log_t
type log_issue_from_errlog = Errlog.t -> log_t type log_issue_from_errlog = Errlog.t -> log_t
let log_issue_from_errlog let log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?pre exn =
err_kind
err_log
?(loc = None)
?(node_id = None)
?(session = None)
?(ltr = None)
?(pre = None)
exn =
let loc = match loc with let loc = match loc with
| None -> State.get_loc () | None -> State.get_loc ()
| Some loc -> loc in | Some loc -> loc in
@ -56,11 +48,11 @@ let log_issue_from_errlog
let log_issue let log_issue
err_kind err_kind
proc_name proc_name
?(loc = None) ?loc
?(node_id = None) ?node_id
?(session = None) ?session
?(ltr = None) ?ltr
?(pre = None) ?pre
exn = exn =
let should_suppress_warnings summary = let should_suppress_warnings summary =
!Config.curr_language = Config.Java && !Config.curr_language = Config.Java &&
@ -72,8 +64,7 @@ let log_issue
| Some summary when should_suppress_warnings summary -> () | Some summary when should_suppress_warnings summary -> ()
| Some summary -> | Some summary ->
let err_log = summary.Specs.attributes.ProcAttributes.err_log in let err_log = summary.Specs.attributes.ProcAttributes.err_log in
log_issue_from_errlog err_kind err_log ~loc:loc ~node_id:node_id log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?pre exn
~session:session ~ltr:ltr ~pre:pre exn
| None -> () | None -> ()
let log_error = log_issue Exceptions.Kerror let log_error = log_issue Exceptions.Kerror

@ -12,11 +12,11 @@ open! Utils
(** Type of functions to report issues to the error_log in a spec. *) (** Type of functions to report issues to the error_log in a spec. *)
type log_t = type log_t =
?loc: Location.t option -> ?loc: Location.t ->
?node_id: (int * int) option -> ?node_id: (int * int) ->
?session: int option -> ?session: int ->
?ltr: Errlog.loc_trace option -> ?ltr: Errlog.loc_trace ->
?pre: Prop.normal Prop.t option -> ?pre: Prop.normal Prop.t ->
exn -> exn ->
unit unit

@ -309,11 +309,11 @@ let mark_instr_fail pre_opt exn =
type log_issue = type log_issue =
Procname.t -> Procname.t ->
?loc: Location.t option -> ?loc: Location.t ->
?node_id: (int * int) option -> ?node_id: (int * int) ->
?session: int option -> ?session: int ->
?ltr: Errlog.loc_trace option -> ?ltr: Errlog.loc_trace ->
?pre: Prop.normal Prop.t option -> ?pre: Prop.normal Prop.t ->
exn -> exn ->
unit unit
@ -326,7 +326,7 @@ let process_execution_failures (log_issue : log_issue) pname =
let desc' = Localise.verbatim_desc ("exception: " ^ Localise.to_string ex_name) in let desc' = Localise.verbatim_desc ("exception: " ^ Localise.to_string ex_name) in
let exn' = Exceptions.Analysis_stops (desc', ml_loc_opt) in let exn' = Exceptions.Analysis_stops (desc', ml_loc_opt) in
log_issue log_issue
pname ~loc: (Some loc) ~node_id: (Some key) ~ltr: (Some loc_trace) ~pre: pre_opt exn' pname ~loc ~node_id:key ~ltr:loc_trace ?pre:pre_opt exn'
| _ -> () in | _ -> () in
NodeHash.iter do_failure !gs.failure_map NodeHash.iter do_failure !gs.failure_map

@ -86,11 +86,11 @@ val mk_find_duplicate_nodes: Cfg.Procdesc.t -> (Cfg.Node.t -> Cfg.NodeSet.t)
type log_issue = type log_issue =
Procname.t -> Procname.t ->
?loc: Location.t option -> ?loc: Location.t ->
?node_id: (int * int) option -> ?node_id: (int * int) ->
?session: int option -> ?session: int ->
?ltr: Errlog.loc_trace option -> ?ltr: Errlog.loc_trace ->
?pre: Prop.normal Prop.t option -> ?pre: Prop.normal Prop.t ->
exn -> exn ->
unit unit

@ -114,7 +114,7 @@ let rec apply_offlist
let err_desc = Errdesc.explain_memory_access deref_str p (State.get_loc ()) in let err_desc = Errdesc.explain_memory_access deref_str p (State.get_loc ()) in
let exn = (Exceptions.Uninitialized_value (err_desc, __POS__)) in let exn = (Exceptions.Uninitialized_value (err_desc, __POS__)) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_warning pname ~pre: pre_opt exn; Reporting.log_warning pname ?pre:pre_opt exn;
Sil.update_inst inst_curr inst Sil.update_inst inst_curr inst
| Sil.Ilookup -> (* a lookup does not change an inst unless it is inst_initial *) | Sil.Ilookup -> (* a lookup does not change an inst unless it is inst_initial *)
lookup_inst := Some inst_curr; lookup_inst := Some inst_curr;
@ -380,7 +380,7 @@ let check_inherently_dangerous_function caller_pname callee_pname =
Exceptions.Inherently_dangerous_function Exceptions.Inherently_dangerous_function
(Localise.desc_inherently_dangerous_function callee_pname) in (Localise.desc_inherently_dangerous_function callee_pname) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop caller_pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop caller_pname) in
Reporting.log_warning caller_pname ~pre: pre_opt exn Reporting.log_warning caller_pname ?pre:pre_opt exn
let proc_is_defined proc_name = let proc_is_defined proc_name =
match AttributesTable.load_attributes proc_name with match AttributesTable.load_attributes proc_name with
@ -423,7 +423,7 @@ let check_arith_norm_exp pname exp prop =
let desc = Errdesc.explain_divide_by_zero div (State.get_node ()) (State.get_loc ()) in let desc = Errdesc.explain_divide_by_zero div (State.get_node ()) (State.get_loc ()) in
let exn = Exceptions.Divide_by_zero (desc, __POS__) in let exn = Exceptions.Divide_by_zero (desc, __POS__) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_warning pname ~pre: pre_opt exn; Reporting.log_warning pname ?pre:pre_opt exn;
Prop.exp_normalize_prop prop exp, prop' Prop.exp_normalize_prop prop exp, prop'
| Some (Attribute.UminusUnsigned (e, typ)), prop' -> | Some (Attribute.UminusUnsigned (e, typ)), prop' ->
let desc = let desc =
@ -431,7 +431,7 @@ let check_arith_norm_exp pname exp prop =
e typ (State.get_node ()) (State.get_loc ()) in e typ (State.get_node ()) (State.get_loc ()) in
let exn = Exceptions.Unary_minus_applied_to_unsigned_expression (desc, __POS__) in let exn = Exceptions.Unary_minus_applied_to_unsigned_expression (desc, __POS__) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_warning pname ~pre: pre_opt exn; Reporting.log_warning pname ?pre:pre_opt exn;
Prop.exp_normalize_prop prop exp, prop' Prop.exp_normalize_prop prop exp, prop'
| None, prop' -> Prop.exp_normalize_prop prop exp, prop' | None, prop' -> Prop.exp_normalize_prop prop exp, prop'
@ -469,7 +469,7 @@ let check_already_dereferenced pname cond prop =
let exn = let exn =
(Exceptions.Null_test_after_dereference (desc, __POS__)) in (Exceptions.Null_test_after_dereference (desc, __POS__)) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop pname) in
Reporting.log_warning pname ~pre: pre_opt exn Reporting.log_warning pname ?pre:pre_opt exn
| None -> () | None -> ()
(** Check whether symbolic execution de-allocated a stack variable or a constant string, (** Check whether symbolic execution de-allocated a stack variable or a constant string,
@ -1064,7 +1064,7 @@ let rec sym_exec tenv current_pdesc _instr (prop_: Prop.normal Prop.t) path
let exn = let exn =
Exceptions.Condition_always_true_false (desc, not (IntLit.iszero i), __POS__) in Exceptions.Condition_always_true_false (desc, not (IntLit.iszero i), __POS__) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop current_pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop current_pname) in
Reporting.log_warning current_pname ~pre: pre_opt exn Reporting.log_warning current_pname ?pre:pre_opt exn
| _ -> () in | _ -> () in
if not Config.report_runtime_exceptions then if not Config.report_runtime_exceptions then
check_already_dereferenced current_pname cond prop__; check_already_dereferenced current_pname cond prop__;
@ -1583,7 +1583,7 @@ and proc_call summary {Builtin.pdesc; tenv; prop_= pre; path; ret_ids; args= act
let err_desc = Localise.desc_return_value_ignored callee_pname loc in let err_desc = Localise.desc_return_value_ignored callee_pname loc in
let exn = (Exceptions.Return_value_ignored (err_desc, __POS__)) in let exn = (Exceptions.Return_value_ignored (err_desc, __POS__)) in
let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop caller_pname) in let pre_opt = State.get_normalized_pre (Abs.abstract_no_symop caller_pname) in
Reporting.log_warning caller_pname ~pre: pre_opt exn in Reporting.log_warning caller_pname ?pre:pre_opt exn in
check_inherently_dangerous_function caller_pname callee_pname; check_inherently_dangerous_function caller_pname callee_pname;
begin begin
let formal_types = IList.map (fun (_, typ) -> typ) (Specs.get_formals summary) in let formal_types = IList.map (fun (_, typ) -> typ) (Specs.get_formals summary) in

@ -373,7 +373,7 @@ let check_path_errors_in_post caller_pname post post_path =
State.set_path new_path path_pos_opt; State.set_path new_path path_pos_opt;
let exn = Exceptions.Divide_by_zero (desc, __POS__) in let exn = Exceptions.Divide_by_zero (desc, __POS__) in
let pre_opt = State.get_normalized_pre (fun _ p -> p) (* Abs.abstract_no_symop *) in let pre_opt = State.get_normalized_pre (fun _ p -> p) (* Abs.abstract_no_symop *) in
Reporting.log_warning caller_pname ~pre: pre_opt exn Reporting.log_warning caller_pname ?pre:pre_opt exn
| _ -> () in | _ -> () in
IList.iter check_attr (Attribute.get_all post) IList.iter check_attr (Attribute.get_all post)

@ -216,7 +216,7 @@ let report_allocation_stack
("new "^constr_str) in ("new "^constr_str) in
let exn = let exn =
Exceptions.Checkers (allocates_memory, Localise.verbatim_desc description) in Exceptions.Checkers (allocates_memory, Localise.verbatim_desc description) in
Reporting.log_error pname ~loc: (Some fst_call_loc) ~ltr: (Some final_trace) exn Reporting.log_error pname ~loc:fst_call_loc ~ltr:final_trace exn
let report_annotation_stack src_annot snk_annot src_pname loc trace stack_str snk_pname call_loc = let report_annotation_stack src_annot snk_annot src_pname loc trace stack_str snk_pname call_loc =
if snk_annot = dummy_constructor_annot if snk_annot = dummy_constructor_annot
@ -239,7 +239,7 @@ let report_annotation_stack src_annot snk_annot src_pname loc trace stack_str sn
else annotation_reachability_error in else annotation_reachability_error in
let exn = let exn =
Exceptions.Checkers (msg, Localise.verbatim_desc description) in Exceptions.Checkers (msg, Localise.verbatim_desc description) in
Reporting.log_error src_pname ~loc: (Some loc) ~ltr: (Some final_trace) exn Reporting.log_error src_pname ~loc ~ltr:final_trace exn
let report_call_stack end_of_stack lookup_next_calls report call_site calls = let report_call_stack end_of_stack lookup_next_calls report call_site calls =
(* TODO: stop using this; we can use the call site instead *) (* TODO: stop using this; we can use the call site instead *)
@ -394,7 +394,7 @@ module Interprocedural = struct
let exn = let exn =
Exceptions.Checkers Exceptions.Checkers
(expensive_overrides_unexpensive, Localise.verbatim_desc description) in (expensive_overrides_unexpensive, Localise.verbatim_desc description) in
Reporting.log_error proc_name ~loc: (Some loc) ~ltr: None exn in Reporting.log_error proc_name ~loc exn in
if expensive then if expensive then
PatternMatch.proc_iter_overridden_methods PatternMatch.proc_iter_overridden_methods

@ -154,7 +154,7 @@ module ST = struct
(Procname.to_string proc_name); (Procname.to_string proc_name);
L.stdout "%s@." description L.stdout "%s@." description
end; end;
Reporting.log_error proc_name ~loc: (Some loc) ~ltr: (Some trace) exn Reporting.log_error proc_name ~loc ~ltr:trace exn
end end
end end

@ -18,7 +18,7 @@ let report_error fragment_typ fld fld_typ pname pdesc =
let description = Localise.desc_fragment_retains_view fragment_typ fld fld_typ pname in let description = Localise.desc_fragment_retains_view fragment_typ fld fld_typ pname in
let exn = Exceptions.Checkers (retained_view, description) in let exn = Exceptions.Checkers (retained_view, description) in
let loc = Cfg.Procdesc.get_loc pdesc in let loc = Cfg.Procdesc.get_loc pdesc in
Reporting.log_error pname ~loc:(Some loc) exn Reporting.log_error pname ~loc exn
let callback_fragment_retains_view_java let callback_fragment_retains_view_java
pname_java { Callbacks.proc_desc; tenv } = pname_java { Callbacks.proc_desc; tenv } =

@ -103,8 +103,8 @@ let log_frontend_issue cfg cg method_decl_opt key issue_desc =
let err_kind = CIssue.severity_of_issue issue in let err_kind = CIssue.severity_of_issue issue in
let method_name = Ast_utils.full_name_of_decl_opt method_decl_opt in let method_name = Ast_utils.full_name_of_decl_opt method_decl_opt in
let key = Hashtbl.hash (key ^ method_name) in let key = Hashtbl.hash (key ^ method_name) in
Reporting.log_issue_from_errlog err_kind errlog exn ~loc:(Some loc) ~ltr:(Some trace) Reporting.log_issue_from_errlog err_kind errlog exn ~loc ~ltr:trace
~node_id:(Some (0, key)) ~node_id:(0, key)
(* General invocation function for checkers (* General invocation function for checkers
Takes Takes

Loading…
Cancel
Save