diff --git a/infer/src/IR/Procname.re b/infer/src/IR/Procname.re index 7fd534928..2af6ca92a 100644 --- a/infer/src/IR/Procname.re +++ b/infer/src/IR/Procname.re @@ -56,7 +56,7 @@ type block = string; /** Type of procedure names. */ -type t = | Java of java | C of c | ObjC_Cpp of objc_cpp | Block of block; +type t = | Java of java | C of c | ObjC_Cpp of objc_cpp | Block of block | Linters_dummy_method; /** Level of verbosity of some to_string functions. */ @@ -227,7 +227,8 @@ let replace_class t new_class => | Java j => Java {...j, class_name: split_classname new_class} | ObjC_Cpp osig => ObjC_Cpp {...osig, class_name: new_class} | C _ - | Block _ => t + | Block _ + | Linters_dummy_method => t }; @@ -269,7 +270,8 @@ let get_method = | ObjC_Cpp name => name.method_name | C (name, _) => name | Block name => name - | Java j => j.method_name; + | Java j => j.method_name + | Linters_dummy_method => "Linters_dummy_method"; /** Return the language of the procedure. */ @@ -278,6 +280,7 @@ let get_language = | ObjC_Cpp _ => Config.Clang | C _ => Config.Clang | Block _ => Config.Clang + | Linters_dummy_method => Config.Clang | Java _ => Config.Java; @@ -535,6 +538,7 @@ let to_unique_id pn => | C (c1, c2) => to_readable_string (c1, c2) true | ObjC_Cpp osig => c_method_to_string osig Verbose | Block name => name + | Linters_dummy_method => "Linters_dummy_method" }; @@ -545,6 +549,7 @@ let to_string p => | C (c1, c2) => to_readable_string (c1, c2) false | ObjC_Cpp osig => c_method_to_string osig Non_verbose | Block name => name + | Linters_dummy_method => to_unique_id p }; @@ -555,6 +560,7 @@ let to_simplified_string withclass::withclass=false p => | C (c1, c2) => to_readable_string (c1, c2) false ^ "()" | ObjC_Cpp osig => c_method_to_string osig Simple | Block _ => "block" + | Linters_dummy_method => to_unique_id p }; @@ -587,6 +593,12 @@ let compare pn1 pn2 => Block s2 ) => string_compare s1 s2 + | ( + Linters_dummy_method, /* Compare fake methods used in linters */ + Linters_dummy_method + ) => 0 + | (Linters_dummy_method, _) => (-1) + | (_, Linters_dummy_method) => 1 | (Block _, _) => (-1) | (_, Block _) => 1 | (ObjC_Cpp osig1, ObjC_Cpp osig2) => c_meth_sig_compare osig1 osig2 diff --git a/infer/src/IR/Procname.rei b/infer/src/IR/Procname.rei index 73c0ddc15..5099fe93e 100644 --- a/infer/src/IR/Procname.rei +++ b/infer/src/IR/Procname.rei @@ -32,7 +32,7 @@ type block; /** Type of procedure names. */ -type t = | Java of java | C of c | ObjC_Cpp of objc_cpp | Block of block; +type t = | Java of java | C of c | ObjC_Cpp of objc_cpp | Block of block | Linters_dummy_method; type java_type = (option string, string); diff --git a/infer/src/checkers/BoundedCallTree.ml b/infer/src/checkers/BoundedCallTree.ml index b7581c012..1a25acbfb 100644 --- a/infer/src/checkers/BoundedCallTree.ml +++ b/infer/src/checkers/BoundedCallTree.ml @@ -124,7 +124,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct frame.Stacktrace.class_str (Procname.objc_cpp_get_class_name objc_cpp_prod) | Procname.C _ -> true (* Needed for test code. *) - | Procname.Block _ -> + | Procname.Block _ | Procname.Linters_dummy_method -> failwith "Proc type not supported by crashcontext: block" in frame.Stacktrace.method_str = (Procname.get_method caller) && matches_class caller in diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index 135a8f210..565225373 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -76,17 +76,17 @@ let while_stmt_checker_list = [CFrontend_checkers.bad_pointer_comparison_warning let checker_for_while_stmt stmt_info cond checker context = checker context stmt_info cond -let get_err_log method_decl_opt loc = +let get_err_log method_decl_opt = let procname = match method_decl_opt with | Some method_decl -> General_utils.procname_of_decl method_decl - | None -> General_utils.get_procname_for_frontend_checks loc in + | None -> Procname.Linters_dummy_method in LintIssues.get_err_log procname (* Add a frontend warning with a description desc at location loc to the errlog of a proc desc *) let log_frontend_issue method_decl_opt key issue_desc = let issue = issue_desc.CIssue.issue in let loc = issue_desc.CIssue.loc in - let errlog = get_err_log method_decl_opt loc in + let errlog = get_err_log method_decl_opt in let err_desc = Errdesc.explain_frontend_warning issue_desc.CIssue.description issue_desc.CIssue.suggestion loc in let name = CIssue.to_string issue in diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index 845c6c034..e63cdcfee 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -712,8 +712,4 @@ struct Pvar.mk mangled_name procname | None -> Pvar.mk (Mangled.from_string name_string) procname - let get_procname_for_frontend_checks loc = - let mangled = string_crc_hex32 (DB.source_file_to_string loc.Location.file) in - Procname.from_string_c_fun ("frontend_checks_" ^ mangled) - end diff --git a/infer/src/clang/cFrontend_utils.mli b/infer/src/clang/cFrontend_utils.mli index 7b457ce17..568225f64 100644 --- a/infer/src/clang/cFrontend_utils.mli +++ b/infer/src/clang/cFrontend_utils.mli @@ -217,8 +217,6 @@ sig val procname_of_decl : Clang_ast_t.decl -> Procname.t - val get_procname_for_frontend_checks : Location.t -> Procname.t - val mk_class_field_name : Clang_ast_t.named_decl_info -> Ident.fieldname val get_var_name_mangled : Clang_ast_t.named_decl_info -> Clang_ast_t.var_decl_info -> diff --git a/infer/tests/codetoanalyze/objc/linters/issues.exp b/infer/tests/codetoanalyze/objc/linters/issues.exp index 733d9bd0a..a1b7a785b 100644 --- a/infer/tests/codetoanalyze/objc/linters/issues.exp +++ b/infer/tests/codetoanalyze/objc/linters/issues.exp @@ -1,6 +1,6 @@ -assign_pointer.m, frontend_checks_006677034375a1c7e7ccfd3694390282, 18, ASSIGN_POINTER_WARNING -assign_pointer.m, frontend_checks_006677034375a1c7e7ccfd3694390282, 20, ASSIGN_POINTER_WARNING -assign_pointer.m, frontend_checks_006677034375a1c7e7ccfd3694390282, 22, ASSIGN_POINTER_WARNING +assign_pointer.m, Linters_dummy_method, 18, ASSIGN_POINTER_WARNING +assign_pointer.m, Linters_dummy_method, 20, ASSIGN_POINTER_WARNING +assign_pointer.m, Linters_dummy_method, 22, ASSIGN_POINTER_WARNING atomic_prop.m, A_bla, 98, DIRECT_ATOMIC_PROPERTY_ACCESS atomic_prop.m, A_bla, 99, DIRECT_ATOMIC_PROPERTY_ACCESS atomic_prop.m, A_readP, 77, DIRECT_ATOMIC_PROPERTY_ACCESS @@ -21,11 +21,11 @@ nsnumber.m, bad1, 13, BAD_POINTER_COMPARISON nsnumber.m, bad2, 18, BAD_POINTER_COMPARISON nsnumber.m, bad3, 23, BAD_POINTER_COMPARISON nsnumber.m, bad4, 43, BAD_POINTER_COMPARISON -registered_observer/Person.m, frontend_checks_e09ed2cbfd6c3584b50a5fd5783367c9, 80, REGISTERED_OBSERVER_BEING_DEALLOCATED -registered_observer/Person.m, frontend_checks_e09ed2cbfd6c3584b50a5fd5783367c9, 97, REGISTERED_OBSERVER_BEING_DEALLOCATED -registered_observer/ViewController3.m, frontend_checks_6eb87af45b67f4c5dda049872d80dc43, 14, REGISTERED_OBSERVER_BEING_DEALLOCATED -strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 15, STRONG_DELEGATE_WARNING -strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 19, STRONG_DELEGATE_WARNING -strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 21, STRONG_DELEGATE_WARNING -strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 23, STRONG_DELEGATE_WARNING -strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 25, STRONG_DELEGATE_WARNING +registered_observer/Person.m, Linters_dummy_method, 80, REGISTERED_OBSERVER_BEING_DEALLOCATED +registered_observer/Person.m, Linters_dummy_method, 97, REGISTERED_OBSERVER_BEING_DEALLOCATED +registered_observer/ViewController3.m, Linters_dummy_method, 14, REGISTERED_OBSERVER_BEING_DEALLOCATED +strong_delegate.m, Linters_dummy_method, 15, STRONG_DELEGATE_WARNING +strong_delegate.m, Linters_dummy_method, 19, STRONG_DELEGATE_WARNING +strong_delegate.m, Linters_dummy_method, 21, STRONG_DELEGATE_WARNING +strong_delegate.m, Linters_dummy_method, 23, STRONG_DELEGATE_WARNING +strong_delegate.m, Linters_dummy_method, 25, STRONG_DELEGATE_WARNING diff --git a/infer/tests/codetoanalyze/objcpp/linters/issues.exp b/infer/tests/codetoanalyze/objcpp/linters/issues.exp index ec24dc3ef..0a98866c6 100644 --- a/infer/tests/codetoanalyze/objcpp/linters/issues.exp +++ b/infer/tests/codetoanalyze/objcpp/linters/issues.exp @@ -8,6 +8,6 @@ componentkit/Test.mm, FooComponent_newWithString:, 85, MUTABLE_LOCAL_VARIABLE_IN componentkit/Test.mm, SomeClass_init, 58, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE cxx_reference_in_block/block.mm, A_foo3:param2:, 37, CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK cxx_reference_in_block/block.mm, A_foo:, 20, CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK -global-var/B.mm, frontend_checks_a1a4821f6afe8cbd5bde0f8905d6f284, 30, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL -global-var/B.mm, frontend_checks_a1a4821f6afe8cbd5bde0f8905d6f284, 32, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL -global-var/B.mm, frontend_checks_a1a4821f6afe8cbd5bde0f8905d6f284, 34, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL +global-var/B.mm, Linters_dummy_method, 30, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL +global-var/B.mm, Linters_dummy_method, 32, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL +global-var/B.mm, Linters_dummy_method, 34, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL