From 8a6aa4b1fd0b52c55ae2dc4301d1ac8741b61430 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Wed, 8 Aug 2018 13:07:05 -0700 Subject: [PATCH] [infer] fix the internal confusion between the issue kind and the severity Summary: The internal concept of "kind" should in fact be named "severity" to match the convention used by many other tools, whereas the internal concept of "severity", i.e "HIGH", "MEDIUM" and "LOW" was never used and in any case redundant with the concept of "info", "warning", "error". This diff maps both the "kind" and "severity" fields to value of the form "advice", "info", "warning", and "error" to be able to progressively migrate the code using the "kind" field. Reviewed By: mbouaziz, jvillard Differential Revision: D9187978 fbshipit-source-id: 447d89f51 --- infer/src/IR/Errlog.ml | 51 +++----- infer/src/IR/Errlog.mli | 9 +- infer/src/IR/Exceptions.ml | 192 ++++++++++------------------ infer/src/IR/Exceptions.mli | 19 +-- infer/src/absint/Checkers.mli | 2 +- infer/src/backend/InferPrint.ml | 28 ++-- infer/src/backend/reporting.ml | 16 +-- infer/src/backend/reporting.mli | 4 +- infer/src/clang/cFrontend_errors.ml | 9 +- infer/src/clang/cIssue.ml | 4 +- infer/src/clang/cIssue.mli | 2 +- infer/src/eradicate/typeErr.ml | 4 +- infer/src/eradicate/typeErr.mli | 2 +- 13 files changed, 128 insertions(+), 214 deletions(-) diff --git a/infer/src/IR/Errlog.ml b/infer/src/IR/Errlog.ml index 27935849f..c94a9c170 100644 --- a/infer/src/IR/Errlog.ml +++ b/infer/src/IR/Errlog.ml @@ -63,11 +63,10 @@ let compute_local_exception_line loc_trace = type node_id_key = {node_id: int; node_key: Caml.Digest.t} type err_key = - { err_kind: Exceptions.err_kind + { severity: Exceptions.severity ; in_footprint: bool ; err_name: IssueType.t - ; err_desc: Localise.error_desc - ; severity: string } + ; err_desc: Localise.error_desc } [@@deriving compare] (** Data associated to a specific error *) @@ -102,13 +101,13 @@ module ErrLogHash = struct (* NOTE: changing the hash function can change the order in which issues are reported. *) let hash key = Hashtbl.hash - (key.err_kind, key.in_footprint, key.err_name, Localise.error_desc_hash key.err_desc) + (key.severity, key.in_footprint, key.err_name, Localise.error_desc_hash key.err_desc) let equal key1 key2 = - [%compare.equal : Exceptions.err_kind * bool * IssueType.t] - (key1.err_kind, key1.in_footprint, key1.err_name) - (key2.err_kind, key2.in_footprint, key2.err_name) + [%compare.equal : Exceptions.severity * bool * IssueType.t] + (key1.severity, key1.in_footprint, key1.err_name) + (key2.severity, key2.in_footprint, key2.err_name) && Localise.error_desc_equal key1.err_desc key2.err_desc end @@ -116,7 +115,7 @@ module ErrLogHash = struct end (** Type of the error log, to be reset once per function. - Map err_kind, fotprint / re - execution flag, error name, + Map severity, fotprint / re - execution flag, error name, error description, severity, to set of err_data. *) type t = ErrDataSet.t ErrLogHash.t @@ -151,7 +150,7 @@ let size filter (err_log: t) = let count = ref 0 in ErrLogHash.iter (fun key err_datas -> - if filter key.err_kind key.in_footprint then count := !count + ErrDataSet.cardinal err_datas + if filter key.severity key.in_footprint then count := !count + ErrDataSet.cardinal err_datas ) err_log ; !count @@ -160,7 +159,7 @@ let size filter (err_log: t) = (** Print errors from error log *) let pp_errors fmt (errlog: t) = let f key _ = - if Exceptions.equal_err_kind key.err_kind Exceptions.Kerror then + if Exceptions.equal_severity key.severity Exceptions.Kerror then F.fprintf fmt "%a@ " IssueType.pp key.err_name in ErrLogHash.iter f errlog @@ -169,7 +168,7 @@ let pp_errors fmt (errlog: t) = (** Print warnings from error log *) let pp_warnings fmt (errlog: t) = let f key _ = - if Exceptions.equal_err_kind key.err_kind Exceptions.Kwarning then + if Exceptions.equal_severity key.severity Exceptions.Kwarning then F.fprintf fmt "%a %a@ " IssueType.pp key.err_name Localise.pp_error_desc key.err_desc in ErrLogHash.iter f errlog @@ -185,7 +184,7 @@ let pp_html source path_to_root fmt (errlog: t) = ErrDataSet.iter (pp_nodeid_session_loc fmt) err_datas in let pp_err_log do_fp ek key err_datas = - if Exceptions.equal_err_kind key.err_kind ek && Bool.equal do_fp key.in_footprint then + if Exceptions.equal_severity key.severity ek && Bool.equal do_fp key.in_footprint then F.fprintf fmt "
%a %a %a" IssueType.pp key.err_name Localise.pp_error_desc key.err_desc pp_eds err_datas in @@ -203,17 +202,6 @@ let pp_html source path_to_root fmt (errlog: t) = ErrLogHash.iter (pp_err_log false Exceptions.Kinfo) errlog -(* I use string in case we want to display a different name to the user*) -let severity_to_str severity = - match severity with - | Exceptions.High -> - "HIGH" - | Exceptions.Medium -> - "MEDIUM" - | Exceptions.Low -> - "LOW" - - (** Add an error description to the error log unless there is one already at the same node + session; return true if added *) let add_issue tbl err_key (err_datas: ErrDataSet.t) : bool = @@ -233,11 +221,11 @@ let update errlog_old errlog_new = ErrLogHash.iter (fun err_key l -> ignore (add_issue errlog_old err_key l)) errlog_new -let log_issue procname ?clang_method_kind err_kind err_log loc (node_id, node_key) session ltr +let log_issue procname ?clang_method_kind severity err_log loc (node_id, node_key) session ltr ?linters_def_file ?doc_url ?access ?extras exn = let lang = Typ.Procname.get_language procname in let error = Exceptions.recognize_exception exn in - let err_kind = match error.kind with Some err_kind -> err_kind | _ -> err_kind in + let severity = Option.value error.severity ~default:severity in let hide_java_loc_zero = (* hide java errors at location zero unless in -developer_mode *) not Config.developer_mode && Language.curr_language_is Java && Int.equal loc.Location.line 0 @@ -264,7 +252,7 @@ let log_issue procname ?clang_method_kind err_kind err_log loc (node_id, node_ke let issue = EventLogger.AnalysisIssue { bug_type= error.name.IssueType.unique_id - ; bug_kind= Exceptions.err_kind_string err_kind + ; bug_kind= Exceptions.severity_string severity ; clang_method_kind= (match lang with Language.Clang -> clang_method_kind | _ -> None) ; exception_triggered_location= error.ocaml_pos ; lang= Language.to_explicit_string lang @@ -289,11 +277,10 @@ let log_issue procname ?clang_method_kind err_kind err_log loc (node_id, node_ke ; extras } in let err_key = - { err_kind + { severity ; in_footprint= !Config.footprint ; err_name= error.name - ; err_desc= error.description - ; severity= severity_to_str error.severity } + ; err_desc= error.description } in add_issue err_log err_key (ErrDataSet.singleton err_data) in @@ -301,9 +288,9 @@ let log_issue procname ?clang_method_kind err_kind err_log loc (node_id, node_ke let print_now () = L.(debug Analysis Medium) "@\n%a@\n@?" - (Exceptions.pp_err ~node_key loc err_kind error.name error.description error.ocaml_pos) + (Exceptions.pp_err ~node_key loc severity error.name error.description error.ocaml_pos) () ; - if err_kind <> Exceptions.Kerror then ( + if not (Exceptions.equal_severity severity Exceptions.Kerror) then ( let warn_str = let pp fmt = Format.fprintf fmt "%s %a" error.name.IssueType.unique_id Localise.pp_error_desc @@ -312,7 +299,7 @@ let log_issue procname ?clang_method_kind err_kind err_log loc (node_id, node_ke F.asprintf "%t" pp in let d = - match err_kind with + match severity with | Exceptions.Kerror -> L.d_error | Exceptions.Kwarning -> diff --git a/infer/src/IR/Errlog.mli b/infer/src/IR/Errlog.mli index 47339e5b6..07cb5c5e4 100644 --- a/infer/src/IR/Errlog.mli +++ b/infer/src/IR/Errlog.mli @@ -37,11 +37,10 @@ val compute_local_exception_line : loc_trace -> int option type node_id_key = private {node_id: int; node_key: Caml.Digest.t} type err_key = private - { err_kind: Exceptions.err_kind + { severity: Exceptions.severity ; in_footprint: bool ; err_name: IssueType.t - ; err_desc: Localise.error_desc - ; severity: string } + ; err_desc: Localise.error_desc } [@@deriving compare] (** Data associated to a specific error *) @@ -87,13 +86,13 @@ 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.err_kind -> bool -> bool) -> t -> int +val size : (Exceptions.severity -> bool -> bool) -> t -> int (** Return the number of elements in the error log which satisfy the filter. *) val update : t -> t -> unit (** Update an old error log with a new one *) val log_issue : - Typ.Procname.t -> ?clang_method_kind:string -> Exceptions.err_kind -> t -> Location.t + Typ.Procname.t -> ?clang_method_kind:string -> Exceptions.severity -> t -> Location.t -> int * Caml.Digest.t -> int -> loc_trace -> ?linters_def_file:string -> ?doc_url:string -> ?access:string -> ?extras:Jsonbug_t.extra -> exn -> unit diff --git a/infer/src/IR/Exceptions.ml b/infer/src/IR/Exceptions.ml index 26c276395..4cf36818d 100644 --- a/infer/src/IR/Exceptions.ml +++ b/infer/src/IR/Exceptions.ml @@ -23,21 +23,15 @@ let string_of_visibility vis = match vis with Exn_user -> "user" | Exn_developer -> "developer" | Exn_system -> "system" -(** severity of bugs *) -type severity = - | High (** high severity bug *) - | Medium (** medium severity bug *) - | Low (** low severity bug *) - (** class of error/warning *) type err_class = Checker | Prover | Nocat | Linters [@@deriving compare] let equal_err_class = [%compare.equal : err_class] -(** kind of error/warning *) -type err_kind = Kwarning | Kerror | Kinfo | Kadvice | Klike [@@deriving compare] +(** severity of the report *) +type severity = Kwarning | Kerror | Kinfo | Kadvice | Klike [@@deriving compare] -let equal_err_kind = [%compare.equal : err_kind] +let equal_severity = [%compare.equal : severity] exception Abduction_case_not_implemented of L.ocaml_pos @@ -151,8 +145,7 @@ type t = ; description: Localise.error_desc ; ocaml_pos: L.ocaml_pos option (** location in the infer source code *) ; visibility: visibility - ; severity: severity - ; kind: err_kind option + ; severity: severity option ; category: err_class } let recognize_exception exn = @@ -163,8 +156,7 @@ let recognize_exception exn = ; description= Localise.no_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Analysis_stops (desc, ocaml_pos_opt) -> let visibility = if Config.analysis_stops then Exn_user else Exn_developer in @@ -172,40 +164,35 @@ let recognize_exception exn = ; description= desc ; ocaml_pos= ocaml_pos_opt ; visibility - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Array_of_pointsto ocaml_pos -> { name= IssueType.array_of_pointsto ; description= Localise.no_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Array_out_of_bounds_l1 (desc, ocaml_pos) -> { name= IssueType.array_out_of_bounds_l1 ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= High - ; kind= Some Kerror + ; severity= Some Kerror ; category= Checker } | Array_out_of_bounds_l2 (desc, ocaml_pos) -> { name= IssueType.array_out_of_bounds_l2 ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Array_out_of_bounds_l3 (desc, ocaml_pos) -> { name= IssueType.array_out_of_bounds_l3 ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Assert_failure (f, l, c) -> let ocaml_pos = (f, l, c, c) in @@ -213,48 +200,42 @@ let recognize_exception exn = ; description= Localise.no_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= High - ; kind= None + ; severity= None ; category= Nocat } | Bad_footprint ocaml_pos -> { name= IssueType.bad_footprint ; description= Localise.no_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Cannot_star ocaml_pos -> { name= IssueType.cannot_star ; description= Localise.no_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Class_cast_exception (desc, ocaml_pos) -> { name= IssueType.class_cast_exception ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Codequery desc -> { name= IssueType.codequery ; description= desc ; ocaml_pos= None ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Comparing_floats_for_equality (desc, ocaml_pos) -> { name= IssueType.comparing_floats_for_equality ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Condition_always_true_false (desc, b, ocaml_pos) -> let name = if b then IssueType.condition_always_true else IssueType.condition_always_false in @@ -262,24 +243,21 @@ let recognize_exception exn = ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Custom_error (error_msg, desc) -> { name= IssueType.from_string error_msg ; description= desc ; ocaml_pos= None ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Checker } | Dummy_exception desc -> { name= IssueType.from_string "Analysis stops" ; description= desc ; ocaml_pos= None ; visibility= Exn_developer - ; severity= Low - ; kind= Some Kinfo + ; severity= Some Kinfo ; category= Checker } | Dangling_pointer_dereference (dko, desc, ocaml_pos) -> let visibility = @@ -293,128 +271,112 @@ let recognize_exception exn = ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Deallocate_stack_variable desc -> { name= IssueType.deallocate_stack_variable ; description= desc ; ocaml_pos= None ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Deallocate_static_memory desc -> { name= IssueType.deallocate_static_memory ; description= desc ; ocaml_pos= None ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Deallocation_mismatch (desc, ocaml_pos) -> { name= IssueType.deallocation_mismatch ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Divide_by_zero (desc, ocaml_pos) -> { name= IssueType.divide_by_zero ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= Some Kerror + ; severity= Some Kerror ; category= Checker } | Double_lock (desc, ocaml_pos) -> { name= IssueType.double_lock ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= Some Kerror + ; severity= Some Kerror ; category= Prover } | Eradicate (kind, desc) -> { name= kind ; description= desc ; ocaml_pos= None ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Empty_vector_access (desc, ocaml_pos) -> { name= IssueType.empty_vector_access ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= Some Kerror + ; severity= Some Kerror ; category= Prover } | Field_not_null_checked (desc, ocaml_pos) -> { name= IssueType.field_not_null_checked ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= Some Kwarning + ; severity= Some Kwarning ; category= Nocat } | Frontend_warning ((name, hum), desc, ocaml_pos) -> { name= IssueType.from_string name ?hum ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= None + ; severity= None ; category= Linters } | Checkers (kind, desc) -> { name= kind ; description= desc ; ocaml_pos= None ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Null_dereference (desc, ocaml_pos) -> { name= IssueType.null_dereference ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Null_test_after_dereference (desc, ocaml_pos) -> { name= IssueType.null_test_after_dereference ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Nocat } | Pointer_size_mismatch (desc, ocaml_pos) -> { name= IssueType.pointer_size_mismatch ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= Some Kerror + ; severity= Some Kerror ; category= Checker } | Inherently_dangerous_function desc -> { name= IssueType.inherently_dangerous_function ; description= desc ; ocaml_pos= None ; visibility= Exn_developer - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Internal_error desc -> { name= IssueType.internal_error ; description= desc ; ocaml_pos= None ; visibility= Exn_developer - ; severity= High - ; kind= None + ; severity= None ; category= Nocat } | Java_runtime_exception (exn_name, _, desc) -> let exn_str = Typ.Name.name exn_name in @@ -422,8 +384,7 @@ let recognize_exception exn = ; description= desc ; ocaml_pos= None ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Leak (fp_part, _, (exn_vis, error_desc), done_array_abstraction, resource, ocaml_pos) -> if done_array_abstraction then @@ -431,16 +392,14 @@ let recognize_exception exn = ; description= error_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= High - ; kind= None + ; severity= None ; category= Prover } else if fp_part then { name= IssueType.leak_in_footprint ; description= error_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= High - ; kind= None + ; severity= None ; category= Prover } else let name = @@ -458,8 +417,7 @@ let recognize_exception exn = ; description= error_desc ; ocaml_pos= Some ocaml_pos ; visibility= exn_vis - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Missing_fld (fld, ocaml_pos) -> let desc = Localise.verbatim_desc (Typ.Fieldname.to_full_string fld) in @@ -467,40 +425,35 @@ let recognize_exception exn = ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Premature_nil_termination (desc, ocaml_pos) -> { name= IssueType.premature_nil_termination ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Parameter_not_null_checked (desc, ocaml_pos) -> { name= IssueType.parameter_not_null_checked ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= Some Kwarning + ; severity= Some Kwarning ; category= Nocat } | Precondition_not_found (desc, ocaml_pos) -> { name= IssueType.precondition_not_found ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Precondition_not_met (desc, ocaml_pos) -> { name= IssueType.precondition_not_met ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Medium - ; kind= Some Kwarning + ; severity= Some Kwarning ; category= Nocat } (* always a warning *) | Retain_cycle (desc, ocaml_pos) -> @@ -508,72 +461,63 @@ let recognize_exception exn = ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Registered_observer_being_deallocated (desc, ocaml_pos) -> { name= IssueType.registered_observer_being_deallocated ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= Some Kerror + ; severity= Some Kerror ; category= Nocat } | Return_expression_required (desc, ocaml_pos) -> { name= IssueType.return_expression_required ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Stack_variable_address_escape (desc, ocaml_pos) -> { name= IssueType.stack_variable_address_escape ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= Some Kerror + ; severity= Some Kerror ; category= Nocat } | Return_statement_missing (desc, ocaml_pos) -> { name= IssueType.return_statement_missing ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Return_value_ignored (desc, ocaml_pos) -> { name= IssueType.return_value_ignored ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | SymOp.Analysis_failure_exe _ -> { name= IssueType.failure_exe ; description= Localise.no_desc ; ocaml_pos= None ; visibility= Exn_system - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Skip_function desc -> { name= IssueType.skip_function ; description= desc ; ocaml_pos= None ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Skip_pointer_dereference (desc, ocaml_pos) -> { name= IssueType.skip_pointer_dereference ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= Some Kinfo + ; severity= Some Kinfo ; category= Nocat } (* always an info *) | Symexec_memory_error ocaml_pos -> @@ -581,56 +525,49 @@ let recognize_exception exn = ; description= Localise.no_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Unary_minus_applied_to_unsigned_expression (desc, ocaml_pos) -> { name= IssueType.unary_minus_applied_to_unsigned_expression ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Unknown_proc -> { name= IssueType.unknown_proc ; description= Localise.no_desc ; ocaml_pos= None ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | Unreachable_code_after (desc, ocaml_pos) -> { name= IssueType.unreachable_code_after ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= Medium - ; kind= None + ; severity= None ; category= Nocat } | Unsafe_guarded_by_access (desc, ocaml_pos) -> { name= IssueType.unsafe_guarded_by_access ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Use_after_free (desc, ocaml_pos) -> { name= IssueType.use_after_free ; description= desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_user - ; severity= High - ; kind= None + ; severity= None ; category= Prover } | Wrong_argument_number ocaml_pos -> { name= IssueType.wrong_argument_number ; description= Localise.no_desc ; ocaml_pos= Some ocaml_pos ; visibility= Exn_developer - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } | exn -> { name= IssueType.failure_exe @@ -638,8 +575,7 @@ let recognize_exception exn = Localise.verbatim_desc (F.asprintf "%a: %s" Exn.pp exn (Caml.Printexc.get_backtrace ())) ; ocaml_pos= None ; visibility= Exn_system - ; severity= Low - ; kind= None + ; severity= None ; category= Nocat } @@ -659,7 +595,7 @@ let print_exception_html s exn = (** string describing an error kind *) -let err_kind_string = function +let severity_string = function | Kwarning -> "WARNING" | Kerror -> @@ -688,8 +624,8 @@ let err_class_string = function let print_key = false (** pretty print an error *) -let pp_err ~node_key loc ekind ex_name desc ocaml_pos_opt fmt () = - let kind = err_kind_string (if equal_err_kind ekind Kinfo then Kwarning else ekind) in +let pp_err ~node_key loc severity ex_name desc ocaml_pos_opt fmt () = + let kind = severity_string (if equal_severity severity Kinfo then Kwarning else severity) in let pp_key fmt k = if print_key then F.fprintf fmt " key: %s " (Caml.Digest.to_hex k) else () in F.fprintf fmt "%a:%d: %s: %a %a%a%a@\n" SourceFile.pp loc.Location.file loc.Location.line kind IssueType.pp ex_name Localise.pp_error_desc desc pp_key node_key L.pp_ocaml_pos_opt diff --git a/infer/src/IR/Exceptions.mli b/infer/src/IR/Exceptions.mli index 3d5f0ee78..072197bd9 100644 --- a/infer/src/IR/Exceptions.mli +++ b/infer/src/IR/Exceptions.mli @@ -21,16 +21,10 @@ val equal_visibility : visibility -> visibility -> bool val string_of_visibility : visibility -> string -(** severity of bugs *) -type severity = - | High (** high severity bug *) - | Medium (** medium severity bug *) - | Low (** low severity bug *) +(** severity of the report *) +type severity = Kwarning | Kerror | Kinfo | Kadvice | Klike [@@deriving compare] -(** kind of error/warning *) -type err_kind = Kwarning | Kerror | Kinfo | Kadvice | Klike [@@deriving compare] - -val equal_err_kind : err_kind -> err_kind -> bool +val equal_severity : severity -> severity -> bool (** class of error *) type err_class = Checker | Prover | Nocat | Linters @@ -153,7 +147,7 @@ exception Wrong_argument_number of Logging.ocaml_pos val err_class_string : err_class -> string (** string describing an error class *) -val err_kind_string : err_kind -> string +val severity_string : severity -> string (** string describing an error kind *) val handle_exception : exn -> bool @@ -163,7 +157,7 @@ val print_exception_html : string -> exn -> unit (** print a description of the exception to the html output *) val pp_err : - node_key:Caml.Digest.t -> Location.t -> err_kind -> IssueType.t -> Localise.error_desc + node_key:Caml.Digest.t -> Location.t -> severity -> IssueType.t -> Localise.error_desc -> Logging.ocaml_pos option -> Format.formatter -> unit -> unit (** pretty print an error *) @@ -172,8 +166,7 @@ type t = ; description: Localise.error_desc ; ocaml_pos: Logging.ocaml_pos option (** location in the infer source code *) ; visibility: visibility - ; severity: severity - ; kind: err_kind option + ; severity: severity option ; category: err_class } val recognize_exception : exn -> t diff --git a/infer/src/absint/Checkers.mli b/infer/src/absint/Checkers.mli index 43dfad8de..c9461cfa7 100644 --- a/infer/src/absint/Checkers.mli +++ b/infer/src/absint/Checkers.mli @@ -13,7 +13,7 @@ module ST : sig val report_error : Tenv.t -> Typ.Procname.t -> Procdesc.t -> IssueType.t -> Location.t -> ?field_name:Typ.Fieldname.t option -> ?origin_loc:Location.t option - -> ?exception_kind:(IssueType.t -> Localise.error_desc -> exn) -> ?severity:Exceptions.err_kind + -> ?exception_kind:(IssueType.t -> Localise.error_desc -> exn) -> ?severity:Exceptions.severity -> string -> unit (** Report an error. *) end diff --git a/infer/src/backend/InferPrint.ml b/infer/src/backend/InferPrint.ml index 47210ffb1..82766804c 100644 --- a/infer/src/backend/InferPrint.ml +++ b/infer/src/backend/InferPrint.ml @@ -49,8 +49,8 @@ let compute_key (bug_type: string) (proc_name: Typ.Procname.t) (filename: string String.concat ~sep:"|" [base_filename; simple_procedure_name; bug_type] -let compute_hash (kind: string) (bug_type: string) (proc_name: Typ.Procname.t) (filename: string) - (qualifier: string) = +let compute_hash (severity: string) (bug_type: string) (proc_name: Typ.Procname.t) + (filename: string) (qualifier: string) = let base_filename = Filename.basename filename in let hashable_procedure_name = Typ.Procname.hashable_name proc_name in let location_independent_qualifier = @@ -59,7 +59,7 @@ let compute_hash (kind: string) (bug_type: string) (proc_name: Typ.Procname.t) ( Str.global_replace (Str.regexp "\\(line \\|column \\|n\\$\\)[0-9]+") "_" qualifier in Utils.better_hash - (kind, bug_type, hashable_procedure_name, base_filename, location_independent_qualifier) + (severity, bug_type, hashable_procedure_name, base_filename, location_independent_qualifier) |> Caml.Digest.to_hex @@ -124,8 +124,8 @@ let summary_values summary = ; vsymop= Summary.Stats.symops stats ; verr= Errlog.size - (fun ekind in_footprint -> - Exceptions.equal_err_kind ekind Exceptions.Kerror && in_footprint ) + (fun severity in_footprint -> + Exceptions.equal_severity severity Exceptions.Kerror && in_footprint ) err_log ; vflags= attributes.ProcAttributes.proc_flags ; vfile= SourceFile.to_string attributes.ProcAttributes.loc.Location.file @@ -161,7 +161,7 @@ module ProcsCsv = struct pp "%s@\n" sv.vproof_trace end -let should_report (issue_kind: Exceptions.err_kind) issue_type error_desc eclass = +let should_report (issue_kind: Exceptions.severity) issue_type error_desc eclass = if not Config.filtering || Exceptions.equal_err_class eclass Exceptions.Linters then true else let issue_kind_is_blacklisted = @@ -231,9 +231,9 @@ module IssuesJson = struct in if key.in_footprint && error_filter source_file key.err_name && should_report_source_file - && should_report key.err_kind key.err_name key.err_desc err_data.err_class + && should_report key.severity key.err_name key.err_desc err_data.err_class then ( - let kind = Exceptions.err_kind_string key.err_kind in + let severity = Exceptions.severity_string key.severity in let bug_type = key.err_name.IssueType.unique_id in let file = SourceFile.to_string source_file in let json_ml_loc = @@ -260,10 +260,10 @@ module IssuesJson = struct in let bug = { Jsonbug_j.bug_class= Exceptions.err_class_string err_data.err_class - ; kind + ; kind= severity ; bug_type ; qualifier - ; severity= key.severity + ; severity ; visibility ; line= err_data.loc.Location.line ; column= err_data.loc.Location.col @@ -271,10 +271,10 @@ module IssuesJson = struct ; procedure_id= Typ.Procname.to_filename procname ; procedure_start_line ; file - ; bug_trace= loc_trace_to_jsonbug_record err_data.loc_trace key.err_kind + ; bug_trace= loc_trace_to_jsonbug_record err_data.loc_trace key.severity ; node_key= err_data.node_id_key.node_key |> Caml.Digest.to_hex ; key= compute_key bug_type procname file - ; hash= compute_hash kind bug_type procname file qualifier + ; hash= compute_hash severity bug_type procname file qualifier ; dotty= error_desc_to_dotty_string key.err_desc ; infer_source_loc= json_ml_loc ; bug_type_hum= key.err_name.IssueType.hum @@ -383,7 +383,7 @@ module IssuesTxt = struct key.in_footprint && error_filter source_file key.err_name && (not Config.filtering || String.is_empty (censored_reason key.err_name source_file)) then - Exceptions.pp_err ~node_key:err_data.node_id_key.node_key err_data.loc key.err_kind + Exceptions.pp_err ~node_key:err_data.node_id_key.node_key err_data.loc key.severity key.err_name key.err_desc None fmt () @@ -473,7 +473,7 @@ module Stats = struct 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 - match key.err_kind with + match key.severity with | Exceptions.Kerror -> found_errors := true ; stats.nerrors <- stats.nerrors + 1 ; diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 91f661249..8c56555de 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -15,7 +15,7 @@ type log_t = type log_issue_from_errlog = Errlog.t -> log_t -let log_issue_from_errlog procname ?clang_method_kind err_kind err_log ?loc ?node_id ?session ?ltr +let log_issue_from_errlog procname ?clang_method_kind severity err_log ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url ?access ?extras exn = let clang_method_kind = Option.map clang_method_kind ~f:ProcAttributes.string_of_clang_method_kind @@ -34,11 +34,11 @@ let log_issue_from_errlog procname ?clang_method_kind err_kind err_log ?loc ?nod match session with None -> (State.get_session () :> int) | Some session -> session in let ltr = match ltr with None -> State.get_loc_trace () | Some ltr -> ltr in - Errlog.log_issue procname ?clang_method_kind err_kind err_log loc node_id session ltr + Errlog.log_issue procname ?clang_method_kind severity err_log loc node_id session ltr ?linters_def_file ?doc_url ?access ?extras exn -let log_issue_from_summary err_kind summary ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url +let log_issue_from_summary severity summary ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url ?access ?extras exn = let attrs = Summary.get_attributes summary in let procname = attrs.proc_name in @@ -58,15 +58,15 @@ let log_issue_from_summary err_kind summary ?loc ?node_id ?session ?ltr ?linters if should_suppress_lint || is_java_generated_method then () (* Skip the reporting *) else let err_log = Summary.get_err_log summary in - log_issue_from_errlog procname ~clang_method_kind err_kind err_log ?loc ?node_id ?session ?ltr + log_issue_from_errlog procname ~clang_method_kind severity err_log ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url ?access ?extras exn -let log_issue_deprecated ?(store_summary= false) err_kind proc_name ?loc ?node_id ?session ?ltr +let log_issue_deprecated ?(store_summary= false) severity proc_name ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url ?access ?extras:_ exn = match Summary.get proc_name with | Some summary -> - log_issue_from_summary err_kind summary ?loc ?node_id ?session ?ltr ?linters_def_file + log_issue_from_summary severity summary ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url ?access exn ; if store_summary then (* TODO (#16348004): This is currently needed as ThreadSafety works as a cluster checker *) @@ -94,10 +94,10 @@ let log_info_deprecated ?(store_summary= false) = log_issue_deprecated ~store_summary Exceptions.Kinfo -let log_issue_external procname ?clang_method_kind err_kind ?loc ?node_id ?session ?ltr +let log_issue_external procname ?clang_method_kind severity ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url ?access ?extras exn = let errlog = IssueLog.get_errlog procname in - log_issue_from_errlog procname ?clang_method_kind err_kind errlog ?loc ?node_id ?session ?ltr + log_issue_from_errlog procname ?clang_method_kind severity errlog ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url ?access ?extras exn diff --git a/infer/src/backend/reporting.mli b/infer/src/backend/reporting.mli index dfb5be58f..bf5d23543 100644 --- a/infer/src/backend/reporting.mli +++ b/infer/src/backend/reporting.mli @@ -32,7 +32,7 @@ val log_info_deprecated : ?store_summary:bool -> Typ.Procname.t -> log_t Use log_info instead *) val log_issue_from_errlog : - Typ.Procname.t -> ?clang_method_kind:ProcAttributes.clang_method_kind -> Exceptions.err_kind + Typ.Procname.t -> ?clang_method_kind:ProcAttributes.clang_method_kind -> Exceptions.severity -> log_issue_from_errlog (** Report an issue of a given kind in the given error log. *) @@ -43,7 +43,7 @@ val log_warning : Summary.t -> log_t (** Add an warning to the given summary. *) val log_issue_external : - Typ.Procname.t -> ?clang_method_kind:ProcAttributes.clang_method_kind -> Exceptions.err_kind + Typ.Procname.t -> ?clang_method_kind:ProcAttributes.clang_method_kind -> Exceptions.severity -> log_t (** Log an issue to the error log in [IssueLog] associated with the given procname. *) diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index a14c4d776..73356d4d9 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -158,7 +158,7 @@ let remove_new_lines_and_whitespace message = String.concat words ~sep:" " -let string_to_err_kind = function +let string_to_severity = function | "WARNING" -> Exceptions.Kwarning | "ERROR" -> @@ -221,7 +221,7 @@ let create_parsed_linters linters_def_file checkers : linter list = | CDesc (av, sugg) when ALVar.is_suggestion_keyword av -> ({issue with suggestion= Some sugg}, cond, wl_paths, bl_paths) | CDesc (av, sev) when ALVar.is_severity_keyword av -> - ({issue with severity= string_to_err_kind sev}, cond, wl_paths, bl_paths) + ({issue with severity= string_to_severity sev}, cond, wl_paths, bl_paths) | CDesc (av, m) when ALVar.is_mode_keyword av -> ({issue with mode= string_to_issue_mode m}, cond, wl_paths, bl_paths) | CDesc (av, doc) when ALVar.is_doc_url_keyword av -> @@ -449,7 +449,6 @@ let log_frontend_issue method_decl_opt (node: Ctl_parser_types.ast_node) in let exn = Exceptions.Frontend_warning ((issue_desc.id, issue_desc.name), err_desc, __POS__) in let trace = [Errlog.make_trace_element 0 issue_desc.loc "" []] in - let err_kind = issue_desc.severity in let key_str = match node with | Decl dec -> @@ -458,8 +457,8 @@ let log_frontend_issue method_decl_opt (node: Ctl_parser_types.ast_node) CAst_utils.generate_key_stmt st in let key = Utils.better_hash key_str in - Reporting.log_issue_from_errlog procname err_kind errlog exn ~loc:issue_desc.loc ~ltr:trace - ~node_id:(0, key) ?linters_def_file ?doc_url:issue_desc.doc_url + Reporting.log_issue_from_errlog procname issue_desc.severity errlog exn ~loc:issue_desc.loc + ~ltr:trace ~node_id:(0, key) ?linters_def_file ?doc_url:issue_desc.doc_url let fill_issue_desc_info_and_log context ~witness ~current_node (issue_desc: CIssue.issue_desc) diff --git a/infer/src/clang/cIssue.ml b/infer/src/clang/cIssue.ml index a3ccf483b..2dfe8d803 100644 --- a/infer/src/clang/cIssue.ml +++ b/infer/src/clang/cIssue.ml @@ -21,7 +21,7 @@ type issue_desc = by removing underscores and capitalizing first letters of words *) loc: Location.t ; (* location in the code *) - severity: Exceptions.err_kind + severity: Exceptions.severity ; suggestion: string option (* an optional suggestion or correction *) } @@ -30,7 +30,7 @@ let string_of_mode m = match m with On -> "On" | Off -> "Off" let pp_issue fmt issue = Format.fprintf fmt "{@\n Id = %s@\n" issue.id ; Format.fprintf fmt "{ Name = %s@\n" (Option.value ~default:"" issue.name) ; - Format.fprintf fmt " Severity = %s@\n" (Exceptions.err_kind_string issue.severity) ; + Format.fprintf fmt " Severity = %s@\n" (Exceptions.severity_string issue.severity) ; Format.fprintf fmt " Mode = %s@\n" (string_of_mode issue.mode) ; Format.fprintf fmt " Description = %s@\n" issue.description ; Format.fprintf fmt " Suggestion = %s@\n" (Option.value ~default:"" issue.suggestion) ; diff --git a/infer/src/clang/cIssue.mli b/infer/src/clang/cIssue.mli index 362315bbd..2364a2572 100644 --- a/infer/src/clang/cIssue.mli +++ b/infer/src/clang/cIssue.mli @@ -21,7 +21,7 @@ type issue_desc = by removing underscores and capitalizing first letters of words *) loc: Location.t ; (* location in the code *) - severity: Exceptions.err_kind + severity: Exceptions.severity ; suggestion: string option (* an optional suggestion or correction *) } diff --git a/infer/src/eradicate/typeErr.ml b/infer/src/eradicate/typeErr.ml index 1c1d8119a..15bced487 100644 --- a/infer/src/eradicate/typeErr.ml +++ b/infer/src/eradicate/typeErr.ml @@ -233,7 +233,7 @@ module Severity = struct None - let err_instance_get_severity tenv err_instance : Exceptions.err_kind option = + let err_instance_get_severity tenv err_instance : Exceptions.severity option = match err_instance with | Call_receiver_annotation_inconsistent (AnnotatedSignature.Nullable, _, _, origin_descr) | Null_field_access (_, _, origin_descr, _) -> @@ -247,7 +247,7 @@ end type st_report_error = Typ.Procname.t -> Procdesc.t -> IssueType.t -> Location.t -> ?field_name:Typ.Fieldname.t option -> ?origin_loc:Location.t option -> ?exception_kind:(IssueType.t -> Localise.error_desc -> exn) - -> ?severity:Exceptions.err_kind -> string -> unit + -> ?severity:Exceptions.severity -> string -> unit (** Report an error right now. *) let report_error_now tenv (st_report_error: st_report_error) err_instance loc pdesc : unit = diff --git a/infer/src/eradicate/typeErr.mli b/infer/src/eradicate/typeErr.mli index 02a113bb1..3270f95f9 100644 --- a/infer/src/eradicate/typeErr.mli +++ b/infer/src/eradicate/typeErr.mli @@ -67,7 +67,7 @@ val node_reset_forall : Procdesc.Node.t -> unit type st_report_error = Typ.Procname.t -> Procdesc.t -> IssueType.t -> Location.t -> ?field_name:Typ.Fieldname.t option -> ?origin_loc:Location.t option -> ?exception_kind:(IssueType.t -> Localise.error_desc -> exn) - -> ?severity:Exceptions.err_kind -> string -> unit + -> ?severity:Exceptions.severity -> string -> unit val report_error : Tenv.t -> st_report_error -> (Procdesc.Node.t -> Procdesc.Node.t) -> err_instance