From 247e785ae4dfed87857078c82ab33f0b32dad6ee Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 11 Sep 2018 06:03:33 -0700 Subject: [PATCH] Reporting cleanup 21: do not keep in-re-execution issues Reviewed By: jeremydubreil Differential Revision: D9754854 fbshipit-source-id: f5853bb00 --- infer/src/IR/Errlog.ml | 43 ++++++++------------------ infer/src/IR/Errlog.mli | 7 ++--- infer/src/backend/InferPrint.ml | 14 +++------ infer/src/backend/reporting.ml | 42 +++++++++++++------------ infer/src/checkers/NullabilityCheck.ml | 5 ++- 5 files changed, 43 insertions(+), 68 deletions(-) diff --git a/infer/src/IR/Errlog.ml b/infer/src/IR/Errlog.ml index db26f95ef..a70d93e7e 100644 --- a/infer/src/IR/Errlog.ml +++ b/infer/src/IR/Errlog.ml @@ -65,11 +65,7 @@ type node = | FrontendNode of {node_key: Procdesc.NodeKey.t} | BackendNode of {node: Procdesc.Node.t} -type err_key = - { severity: Exceptions.severity - ; in_footprint: bool - ; err_name: IssueType.t - ; err_desc: Localise.error_desc } +type err_key = {severity: Exceptions.severity; err_name: IssueType.t; err_desc: Localise.error_desc} [@@deriving compare] (** Data associated to a specific error *) @@ -103,15 +99,11 @@ module ErrLogHash = struct type t = err_key (* NOTE: changing the hash function can change the order in which issues are reported. *) - let hash key = - Hashtbl.hash - (key.severity, key.in_footprint, key.err_name, Localise.error_desc_hash key.err_desc) - + let hash key = Hashtbl.hash (key.severity, key.err_name, Localise.error_desc_hash key.err_desc) let equal key1 key2 = - [%compare.equal: Exceptions.severity * bool * IssueType.t] - (key1.severity, key1.in_footprint, key1.err_name) - (key2.severity, key2.in_footprint, key2.err_name) + [%compare.equal: Exceptions.severity * IssueType.t] (key1.severity, key1.err_name) + (key2.severity, key2.err_name) && Localise.error_desc_equal key1.err_desc key2.err_desc end @@ -147,8 +139,7 @@ let size filter (err_log : t) = let count = ref 0 in ErrLogHash.iter (fun key err_datas -> - if filter key.severity key.in_footprint then count := !count + ErrDataSet.cardinal err_datas - ) + if filter key.severity then count := !count + ErrDataSet.cardinal err_datas ) err_log ; !count @@ -180,20 +171,17 @@ let pp_html source path_to_root fmt (errlog : t) = in ErrDataSet.iter (pp_nodeid_session_loc fmt) err_datas in - let pp_err_log do_fp ek key err_datas = - if Exceptions.equal_severity key.severity ek && Bool.equal do_fp key.in_footprint then + let pp_err_log ek key err_datas = + if Exceptions.equal_severity key.severity ek then F.fprintf fmt "
%a %a %a" IssueType.pp key.err_name Localise.pp_error_desc key.err_desc pp_eds err_datas in - let pp severity is_footprint phase = - F.fprintf fmt "%a%s DURING %s@\n" Io_infer.Html.pp_hline () - (Exceptions.severity_string severity) - phase ; - ErrLogHash.iter (pp_err_log is_footprint severity) errlog + let pp severity = + F.fprintf fmt "%a%s DURING FOOTPRINT@\n" Io_infer.Html.pp_hline () + (Exceptions.severity_string severity) ; + ErrLogHash.iter (pp_err_log severity) errlog in - List.iter - Exceptions.[Advice; Error; Info; Like; Warning] - ~f:(fun severity -> pp severity true "FOOTPRINT" ; pp severity false "RE-EXECUTION") + List.iter Exceptions.[Advice; Error; Info; Like; Warning] ~f:pp (** Add an error description to the error log unless there is @@ -286,12 +274,7 @@ let log_issue procname ~clang_method_kind severity err_log ~loc ~node ~session ~ ; access ; extras } in - let err_key = - { severity - ; in_footprint= !Config.footprint - ; err_name= error.name - ; err_desc= error.description } - in + let err_key = {severity; err_name= error.name; err_desc= error.description} in add_issue err_log err_key (ErrDataSet.singleton err_data) in let should_print_now = match exn with Exceptions.Internal_error _ -> true | _ -> added in diff --git a/infer/src/IR/Errlog.mli b/infer/src/IR/Errlog.mli index 513525543..afebd1d83 100644 --- a/infer/src/IR/Errlog.mli +++ b/infer/src/IR/Errlog.mli @@ -40,10 +40,7 @@ type node = | BackendNode of {node: Procdesc.Node.t} type err_key = private - { severity: Exceptions.severity - ; in_footprint: bool - ; err_name: IssueType.t - ; err_desc: Localise.error_desc } + {severity: Exceptions.severity; err_name: IssueType.t; err_desc: Localise.error_desc} [@@deriving compare] (** Data associated to a specific error *) @@ -88,7 +85,7 @@ val pp_warnings : Format.formatter -> t -> unit val pp_html : SourceFile.t -> DB.Results_dir.path -> Format.formatter -> t -> unit (** Print an error log in html format *) -val size : (Exceptions.severity -> bool -> bool) -> t -> int +val size : (Exceptions.severity -> bool) -> t -> int (** Return the number of elements in the error log which satisfy the filter. *) val update : t -> t -> unit diff --git a/infer/src/backend/InferPrint.ml b/infer/src/backend/InferPrint.ml index 48cead321..b5ff8a752 100644 --- a/infer/src/backend/InferPrint.ml +++ b/infer/src/backend/InferPrint.ml @@ -122,11 +122,7 @@ let summary_values summary = ; vspecs= List.length specs ; vto= Summary.Stats.failure_kind_to_string stats ; vsymop= Summary.Stats.symops stats - ; verr= - Errlog.size - (fun severity in_footprint -> - Exceptions.equal_severity severity Exceptions.Error && in_footprint ) - err_log + ; verr= Errlog.size (Exceptions.equal_severity Exceptions.Error) err_log ; vflags= attributes.ProcAttributes.proc_flags ; vfile= SourceFile.to_string attributes.ProcAttributes.loc.Location.file ; vline= attributes.ProcAttributes.loc.Location.line @@ -264,8 +260,7 @@ module JsonIssuePrinter = MakeJsonListPrinter (struct (not (SourceFile.is_infer_model source_file)) || Config.debug_mode || Config.debug_exceptions in if - err_key.in_footprint - && error_filter source_file err_key.err_name + error_filter source_file err_key.err_name && should_report_source_file && should_report err_key.severity err_key.err_name err_key.err_desc err_data.err_class then @@ -451,8 +446,7 @@ module IssuesTxt = struct err_data.loc.Location.file in if - key.in_footprint - && error_filter source_file key.err_name + error_filter source_file key.err_name && ((not Config.filtering) || String.is_empty (censored_reason key.err_name source_file)) then Exceptions.pp_err err_data.loc key.severity key.err_name key.err_desc None fmt () @@ -543,7 +537,7 @@ module Stats = struct let found_errors = ref false in let process_row (key : Errlog.err_key) (err_data : Errlog.err_data) = let type_str = key.err_name.IssueType.unique_id in - if key.in_footprint && error_filter key.err_name then + if error_filter key.err_name then match key.severity with | Exceptions.Error -> found_errors := true ; diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index bd29bf36a..eb23cfd33 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -50,21 +50,22 @@ let log_issue_from_summary severity summary ~node ~session ~loc ~ltr ?extras exn let log_issue_deprecated_using_state severity proc_name ?node ?loc ?ltr exn = - match Summary.get proc_name with - | Some summary -> - let node = - let node = match node with None -> State.get_node_exn () | Some node -> node in - Errlog.BackendNode {node} - in - let session = State.get_session () in - let loc = match loc with None -> State.get_loc_exn () | Some loc -> loc in - let ltr = match ltr with None -> State.get_loc_trace () | Some ltr -> ltr in - log_issue_from_summary severity summary ~node ~session ~loc ~ltr exn - | None -> - L.(die InternalError) - "Trying to report error on procedure %a, but cannot because no summary exists for this \ - procedure. Did you mean to log the error on the caller of %a instead?" - Typ.Procname.pp proc_name Typ.Procname.pp proc_name + if !Config.footprint then + match Summary.get proc_name with + | Some summary -> + let node = + let node = match node with None -> State.get_node_exn () | Some node -> node in + Errlog.BackendNode {node} + in + let session = State.get_session () in + let loc = match loc with None -> State.get_loc_exn () | Some loc -> loc in + let ltr = match ltr with None -> State.get_loc_trace () | Some ltr -> ltr in + log_issue_from_summary severity summary ~node ~session ~loc ~ltr exn + | None -> + L.(die InternalError) + "Trying to report error on procedure %a, but cannot because no summary exists for this \ + procedure. Did you mean to log the error on the caller of %a instead?" + Typ.Procname.pp proc_name Typ.Procname.pp proc_name let log_issue_from_summary_simplified severity summary ~loc ?(ltr = []) ?extras exn = @@ -84,11 +85,12 @@ let log_issue_external procname severity ~loc ~ltr ?access issue_type error_mess let log_error_using_state summary exn = - let node = Errlog.BackendNode {node= State.get_node_exn ()} in - let session = State.get_session () in - let loc = State.get_loc_exn () in - let ltr = State.get_loc_trace () in - log_issue_from_summary Exceptions.Error summary ~node ~session ~loc ~ltr exn + if !Config.footprint then + let node = Errlog.BackendNode {node= State.get_node_exn ()} in + let session = State.get_session () in + let loc = State.get_loc_exn () in + let ltr = State.get_loc_trace () in + log_issue_from_summary Exceptions.Error summary ~node ~session ~loc ~ltr exn let is_suppressed ?(field_name = None) tenv proc_desc kind = diff --git a/infer/src/checkers/NullabilityCheck.ml b/infer/src/checkers/NullabilityCheck.ml index 956fb2b26..cabc5ecd4 100644 --- a/infer/src/checkers/NullabilityCheck.ml +++ b/infer/src/checkers/NullabilityCheck.ml @@ -74,10 +74,9 @@ module TransferFunctions (CFG : ProcCfg.S) = struct if not Config.filtering then false else Errlog.fold - (fun {Errlog.err_name; err_desc; in_footprint} {Errlog.loc} found_confict -> + (fun {Errlog.err_name; err_desc} {Errlog.loc} found_confict -> found_confict - || in_footprint - && IssueType.equal err_name IssueType.null_dereference + || IssueType.equal err_name IssueType.null_dereference && Location.equal loc report_location && Localise.error_desc_is_reportable_bucket err_desc ) (Summary.get_err_log summary) false