diff --git a/infer/src/IR/Errlog.ml b/infer/src/IR/Errlog.ml index a60bc019d..31910b9e9 100644 --- a/infer/src/IR/Errlog.ml +++ b/infer/src/IR/Errlog.ml @@ -234,8 +234,9 @@ 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 err_kind err_log loc (node_id, node_key) session ltr ?linters_def_file - ?doc_url ?access exn = +let log_issue procname ?clang_method_kind err_kind err_log loc (node_id, node_key) session ltr + ?linters_def_file ?doc_url ?access 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 hide_java_loc_zero = @@ -263,11 +264,11 @@ let log_issue procname err_kind err_log loc (node_id, node_key) session ltr ?lin ( if exn_developer then let issue = EventLogger.AnalysisIssue - (* TODO: Add clang_method_kind field (T26423401) *) { bug_type= error.name.IssueType.unique_id ; bug_kind= Exceptions.err_kind_string err_kind + ; clang_method_kind= (match lang with Language.Clang -> clang_method_kind | _ -> None) ; exception_triggered_location= error.ocaml_pos - ; lang= Typ.Procname.get_language procname |> Language.to_explicit_string + ; lang= Language.to_explicit_string lang ; procedure_name= Typ.Procname.to_string procname ; source_location= loc } in diff --git a/infer/src/IR/Errlog.mli b/infer/src/IR/Errlog.mli index da269a69f..ca7011e31 100644 --- a/infer/src/IR/Errlog.mli +++ b/infer/src/IR/Errlog.mli @@ -93,5 +93,6 @@ val update : t -> t -> unit (** Update an old error log with a new one *) val log_issue : - Typ.Procname.t -> Exceptions.err_kind -> t -> Location.t -> int * Caml.Digest.t -> int - -> loc_trace -> ?linters_def_file:string -> ?doc_url:string -> ?access:string -> exn -> unit + Typ.Procname.t -> ?clang_method_kind:string -> Exceptions.err_kind -> t -> Location.t + -> int * Caml.Digest.t -> int -> loc_trace -> ?linters_def_file:string -> ?doc_url:string + -> ?access:string -> exn -> unit diff --git a/infer/src/IR/ProcAttributes.ml b/infer/src/IR/ProcAttributes.ml index a62e05b84..10b35a5db 100644 --- a/infer/src/IR/ProcAttributes.ml +++ b/infer/src/IR/ProcAttributes.ml @@ -33,7 +33,7 @@ type clang_method_kind = | C_FUNCTION [@@deriving compare] -let clang_method_kind_equal = [%compare.equal : clang_method_kind] +let equal_clang_method_kind = [%compare.equal : clang_method_kind] let string_of_clang_method_kind = function | CPP_INSTANCE -> diff --git a/infer/src/IR/ProcAttributes.mli b/infer/src/IR/ProcAttributes.mli index 6c79e4f84..1d9b73b75 100644 --- a/infer/src/IR/ProcAttributes.mli +++ b/infer/src/IR/ProcAttributes.mli @@ -23,7 +23,7 @@ type clang_method_kind = | C_FUNCTION [@@deriving compare] -val clang_method_kind_equal : clang_method_kind -> clang_method_kind -> bool +val equal_clang_method_kind : clang_method_kind -> clang_method_kind -> bool val string_of_clang_method_kind : clang_method_kind -> string diff --git a/infer/src/backend/prover.ml b/infer/src/backend/prover.ml index 03c0a8021..5a2ca6748 100644 --- a/infer/src/backend/prover.ml +++ b/infer/src/backend/prover.ml @@ -996,12 +996,12 @@ let check_inconsistency_base tenv prop = let is_objc_instance_self pvar = Language.equal language Clang && Mangled.equal (Pvar.get_name pvar) (Mangled.from_string "self") - && ProcAttributes.clang_method_kind_equal procedure_attr.ProcAttributes.clang_method_kind + && ProcAttributes.equal_clang_method_kind procedure_attr.ProcAttributes.clang_method_kind ProcAttributes.OBJC_INSTANCE in let is_cpp_this pvar = Language.equal language Clang && Pvar.is_this pvar - && ProcAttributes.clang_method_kind_equal procedure_attr.ProcAttributes.clang_method_kind + && ProcAttributes.equal_clang_method_kind procedure_attr.ProcAttributes.clang_method_kind ProcAttributes.CPP_INSTANCE in let do_hpred = function diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 2963b0772..6c79c20bd 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -16,8 +16,11 @@ type log_t = type log_issue_from_errlog = Errlog.t -> log_t -let log_issue_from_errlog procname err_kind err_log ?loc ?node_id ?session ?ltr ?linters_def_file - ?doc_url ?access exn = +let log_issue_from_errlog procname ?clang_method_kind err_kind err_log ?loc ?node_id ?session ?ltr + ?linters_def_file ?doc_url ?access exn = + let clang_method_kind = + Option.map clang_method_kind ~f:ProcAttributes.string_of_clang_method_kind + in let issue_type = (Exceptions.recognize_exception exn).name in if not Config.filtering (* no-filtering takes priority *) || issue_type.IssueType.enabled then let loc = match loc with None -> State.get_loc () | Some loc -> loc in @@ -32,13 +35,15 @@ let log_issue_from_errlog procname err_kind err_log ?loc ?node_id ?session ?ltr 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 err_kind err_log loc node_id session ltr ?linters_def_file ?doc_url - ?access exn + Errlog.log_issue procname ?clang_method_kind err_kind err_log loc node_id session ltr + ?linters_def_file ?doc_url ?access exn let log_issue_from_summary err_kind summary ?loc ?node_id ?session ?ltr ?linters_def_file ?doc_url ?access exn = - let procname = Specs.get_proc_name summary in + let attrs = Specs.get_attributes summary in + let procname = attrs.proc_name in + let clang_method_kind = attrs.clang_method_kind in let is_java_generated_method = match procname with | Typ.Procname.Java java_pname -> @@ -54,8 +59,8 @@ 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 = Specs.get_err_log summary in - log_issue_from_errlog procname err_kind err_log ?loc ?node_id ?session ?ltr ?linters_def_file - ?doc_url ?access exn + log_issue_from_errlog procname ~clang_method_kind err_kind err_log ?loc ?node_id ?session ?ltr + ?linters_def_file ?doc_url ?access exn let log_issue_deprecated ?(store_summary= false) err_kind proc_name ?loc ?node_id ?session ?ltr diff --git a/infer/src/backend/reporting.mli b/infer/src/backend/reporting.mli index d208694f9..7319098b2 100644 --- a/infer/src/backend/reporting.mli +++ b/infer/src/backend/reporting.mli @@ -32,7 +32,9 @@ val log_info_deprecated : ?store_summary:bool -> Typ.Procname.t -> log_t DEPRECATED as it can create race conditions between checkers. Use log_info instead *) -val log_issue_from_errlog : Typ.Procname.t -> Exceptions.err_kind -> log_issue_from_errlog +val log_issue_from_errlog : + Typ.Procname.t -> ?clang_method_kind:ProcAttributes.clang_method_kind -> Exceptions.err_kind + -> log_issue_from_errlog (** Report an issue of a given kind in the given error log. *) val log_error : Specs.summary -> log_t diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index f18f90656..20f90b74a 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -1277,7 +1277,7 @@ let rec sym_exec tenv current_pdesc instr_ (prop_: Prop.normal Prop.t) path prop path | None, false -> let is_objc_instance_method = - ProcAttributes.clang_method_kind_equal + ProcAttributes.equal_clang_method_kind attrs.ProcAttributes.clang_method_kind ProcAttributes.OBJC_INSTANCE in skip_call ~is_objc_instance_method ~reason:"function or method not found" diff --git a/infer/src/base/EventLogger.ml b/infer/src/base/EventLogger.ml index 518abf8e4..ac4623406 100644 --- a/infer/src/base/EventLogger.ml +++ b/infer/src/base/EventLogger.ml @@ -74,6 +74,7 @@ end type analysis_issue = { bug_kind: string ; bug_type: string + ; clang_method_kind: string option ; exception_triggered_location: Logging.ocaml_pos option ; lang: string ; procedure_name: string @@ -83,6 +84,7 @@ let create_analysis_issue_row base record = let open JsonBuilder in base |> add_string ~key:"bug_kind" ~data:record.bug_kind |> add_string ~key:"bug_type" ~data:record.bug_type + |> add_string_opt ~key:"clang_method_kind" ~data:record.clang_method_kind |> add_string_opt ~key:"exception_triggered_location" ~data:(Option.map ~f:Logging.ocaml_pos_to_string record.exception_triggered_location) |> add_string ~key:"lang" ~data:record.lang diff --git a/infer/src/base/EventLogger.mli b/infer/src/base/EventLogger.mli index f58c15827..00fdfd1a1 100644 --- a/infer/src/base/EventLogger.mli +++ b/infer/src/base/EventLogger.mli @@ -10,6 +10,7 @@ type analysis_issue = { bug_kind: string ; bug_type: string + ; clang_method_kind: string option ; exception_triggered_location: Logging.ocaml_pos option ; lang: string ; procedure_name: string diff --git a/infer/src/checkers/NullabilityCheck.ml b/infer/src/checkers/NullabilityCheck.ml index 6042a871c..b52bcbd43 100644 --- a/infer/src/checkers/NullabilityCheck.ml +++ b/infer/src/checkers/NullabilityCheck.ml @@ -41,7 +41,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct | _ -> Option.exists ~f:(fun attributes -> - ProcAttributes.clang_method_kind_equal attributes.ProcAttributes.clang_method_kind + ProcAttributes.equal_clang_method_kind attributes.ProcAttributes.clang_method_kind ProcAttributes.CPP_INSTANCE ) (Specs.proc_resolve_attributes callee_pname) @@ -49,7 +49,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_objc_instance_method callee_pname = Option.exists ~f:(fun attributes -> - ProcAttributes.clang_method_kind_equal attributes.ProcAttributes.clang_method_kind + ProcAttributes.equal_clang_method_kind attributes.ProcAttributes.clang_method_kind ProcAttributes.OBJC_INSTANCE ) (Specs.proc_resolve_attributes callee_pname) diff --git a/infer/src/clang/cContext.ml b/infer/src/clang/cContext.ml index 051e8110e..d8371ddfa 100644 --- a/infer/src/clang/cContext.ml +++ b/infer/src/clang/cContext.ml @@ -71,7 +71,7 @@ let rec is_objc_instance context = is_objc_instance outer_context | None -> let attrs = Procdesc.get_attributes context.procdesc in - ProcAttributes.clang_method_kind_equal attrs.ProcAttributes.clang_method_kind + ProcAttributes.equal_clang_method_kind attrs.ProcAttributes.clang_method_kind ProcAttributes.OBJC_INSTANCE diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 3b0abc96a..3b3cd40e6 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -349,7 +349,7 @@ let get_formal_parameters tenv ms = && CFrontend_config.equal_clang_lang ms.CMethodSignature.lang CFrontend_config.CPP in is_objc_self - && ProcAttributes.clang_method_kind_equal ms.CMethodSignature.method_kind + && ProcAttributes.equal_clang_method_kind ms.CMethodSignature.method_kind ProcAttributes.OBJC_INSTANCE || is_cxx_this in