diff --git a/infer/src/backend/ondemand.ml b/infer/src/backend/ondemand.ml index c983d82a5..00fa8b067 100644 --- a/infer/src/backend/ondemand.ml +++ b/infer/src/backend/ondemand.ml @@ -169,37 +169,41 @@ let run_proc_analysis analyze_proc ~caller_pdesc callee_pdesc = let analyze_proc_desc ?caller_pdesc callee_pdesc = - let cache = Lazy.force cached_results in let callee_pname = Procdesc.get_proc_name callee_pdesc in - try Typ.Procname.Hash.find cache callee_pname with Not_found -> - let summary_option = - let callbacks = Option.value_exn !callbacks_ref in - let proc_attributes = Procdesc.get_attributes callee_pdesc in - if should_be_analyzed callee_pname proc_attributes then - Some (run_proc_analysis callbacks.analyze_ondemand ~caller_pdesc callee_pdesc) - else Specs.get_summary callee_pname - in - if not (is_active callee_pname) then Typ.Procname.Hash.add cache callee_pname summary_option ; - summary_option + if is_active callee_pname then None + else + let cache = Lazy.force cached_results in + try Typ.Procname.Hash.find cache callee_pname with Not_found -> + let summary_option = + let callbacks = Option.value_exn !callbacks_ref in + let proc_attributes = Procdesc.get_attributes callee_pdesc in + if should_be_analyzed callee_pname proc_attributes then + Some (run_proc_analysis callbacks.analyze_ondemand ~caller_pdesc callee_pdesc) + else Specs.get_summary callee_pname + in + Typ.Procname.Hash.add cache callee_pname summary_option ; + summary_option (** analyze_proc_name curr_pdesc proc_name performs an on-demand analysis of proc_name triggered during the analysis of curr_pname *) let analyze_proc_name ?caller_pdesc callee_pname = - let cache = Lazy.force cached_results in - try Typ.Procname.Hash.find cache callee_pname with Not_found -> - let summary_option = - let callbacks = Option.value_exn !callbacks_ref in - if procedure_should_be_analyzed callee_pname then - match callbacks.get_proc_desc callee_pname with - | Some callee_pdesc -> - analyze_proc_desc ?caller_pdesc callee_pdesc - | None -> - Specs.get_summary callee_pname - else Specs.get_summary callee_pname - in - if not (is_active callee_pname) then Typ.Procname.Hash.add cache callee_pname summary_option ; - summary_option + if is_active callee_pname then None + else + let cache = Lazy.force cached_results in + try Typ.Procname.Hash.find cache callee_pname with Not_found -> + let summary_option = + let callbacks = Option.value_exn !callbacks_ref in + if procedure_should_be_analyzed callee_pname then + match callbacks.get_proc_desc callee_pname with + | Some callee_pdesc -> + analyze_proc_desc ?caller_pdesc callee_pdesc + | None -> + Specs.get_summary callee_pname + else Specs.get_summary callee_pname + in + Typ.Procname.Hash.add cache callee_pname summary_option ; + summary_option (** Find a proc desc for the procedure, perhaps loading it from disk. *) diff --git a/infer/tests/codetoanalyze/cpp/errors/issues.exp b/infer/tests/codetoanalyze/cpp/errors/issues.exp index a011d4755..8cf50af67 100644 --- a/infer/tests/codetoanalyze/cpp/errors/issues.exp +++ b/infer/tests/codetoanalyze/cpp/errors/issues.exp @@ -68,7 +68,6 @@ codetoanalyze/cpp/errors/npe/npe_added_to_b1.cpp, npe_added_to_b1::causes_npe, 2 codetoanalyze/cpp/errors/npe/npe_added_to_b1.cpp, npe_added_to_b1::causes_npe_person, 2, NULL_DEREFERENCE, [start of procedure npe_added_to_b1::causes_npe_person(),start of procedure Person,return from a call to npe_added_to_b1::Person_Person,start of procedure npe_added_to_b1::deref_person()] codetoanalyze/cpp/errors/npe/null_returned_by_method.cpp, testNullDeref, 3, NULL_DEREFERENCE, [start of procedure testNullDeref(),Condition is true,start of procedure getNull,return from a call to XFactory_getNull] codetoanalyze/cpp/errors/npe/object_deref.cpp, object_deref::derefNullField, 2, NULL_DEREFERENCE, [start of procedure object_deref::derefNullField(),start of procedure object_deref::getNull(),return from a call to object_deref::getNull] -codetoanalyze/cpp/errors/npe/recursive_call.cpp, recursive_call::test_rec2_ok_FP, 2, PRECONDITION_NOT_MET, [start of procedure recursive_call::test_rec2_ok_FP(),start of procedure F,return from a call to recursive_call::F_F,start of procedure F,return from a call to recursive_call::F_F] codetoanalyze/cpp/errors/npe/skip_function_with_const_formals.cpp, FP_const_skip2_then_split_case_ok, 5, MEMORY_LEAK, [start of procedure FP_const_skip2_then_split_case_ok(),Skipping skip_const2(): function or method not found,start of procedure test_pointer(),Condition is true,return from a call to test_pointer] codetoanalyze/cpp/errors/npe/skip_function_with_const_formals.cpp, FP_const_skip_then_split_case_ok, 6, MEMORY_LEAK, [start of procedure FP_const_skip_then_split_case_ok(),Skipping skip_const(): function or method not found,start of procedure test_pointer(),Condition is true,return from a call to test_pointer] codetoanalyze/cpp/errors/npe/skip_function_with_const_formals.cpp, FP_typedef_skip_then_split_case_ok, 2, MEMORY_LEAK, [start of procedure FP_typedef_skip_then_split_case_ok(),Skipping skip_typedef(): function or method not found] diff --git a/infer/tests/codetoanalyze/cpp/errors/npe/recursive_call.cpp b/infer/tests/codetoanalyze/cpp/errors/npe/recursive_call.cpp index 6d99c3a72..25f8c3173 100644 --- a/infer/tests/codetoanalyze/cpp/errors/npe/recursive_call.cpp +++ b/infer/tests/codetoanalyze/cpp/errors/npe/recursive_call.cpp @@ -44,9 +44,9 @@ A* rec2(F f, A* a = nullptr) { return a->getptr(); } -int test_rec2_ok_FP() { +int test_rec2_ok() { F f; - return rec2(f)->f; // PRECONDITION_NOT_MET + return rec2(f)->f; } } // namespace recursive_call