From 436e5340f35ba6d5bb1c717da646a96b9e1e0d41 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Thu, 29 Mar 2018 08:09:04 -0700 Subject: [PATCH] [retain cycles] Move the retain cycle check to sym_exec_wrapper to get the path of the last instruction executed Reviewed By: mbouaziz Differential Revision: D7443580 fbshipit-source-id: 4512675 --- infer/src/biabduction/SymExec.ml | 7 ++++++- infer/src/biabduction/Tabulation.ml | 9 ++------- .../tests/codetoanalyze/objc/errors/issues.exp | 18 +++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/infer/src/biabduction/SymExec.ml b/infer/src/biabduction/SymExec.ml index ac13e26da..ad106df65 100644 --- a/infer/src/biabduction/SymExec.ml +++ b/infer/src/biabduction/SymExec.ml @@ -1034,7 +1034,6 @@ let execute_store ?(report_deref_errors= true) pname pdesc tenv lhs_exp typ rhs_ let prop_list = List.rev (List.fold ~f:(execute_store_ pdesc tenv n_rhs_exp) ~init:[] iter_list) in - if !Config.footprint then List.iter ~f:(RetainCycles.report_cycle tenv pname) prop_list ; prop_list with Rearrange.ARRAY_ACCESS -> if Int.equal Config.array_level 0 then assert false else [prop_] @@ -1792,6 +1791,12 @@ and sym_exec_wrapper exe_env handle_exn tenv proc_cfg instr ((prop: Prop.normal let post_process_result fav_normal p path = let p' = prop_normal_to_primed fav_normal p in State.set_path path None ; + (* Check for retain cycles after assignments and method calls *) + ( match instr with + | (Sil.Store _ | Sil.Call _) when !Config.footprint -> + List.iter ~f:(RetainCycles.report_cycle tenv pname) [p] + | _ -> + () ) ; let node_has_abstraction node = let instr_is_abstraction = function Sil.Abstract _ -> true | _ -> false in List.exists ~f:instr_is_abstraction (ProcCfg.Exceptional.instrs node) diff --git a/infer/src/biabduction/Tabulation.ml b/infer/src/biabduction/Tabulation.ml index a533522da..c42fdaa4b 100644 --- a/infer/src/biabduction/Tabulation.ml +++ b/infer/src/biabduction/Tabulation.ml @@ -1262,7 +1262,7 @@ let prop_pure_to_footprint tenv (p: 'a Prop.t) : Prop.normal Prop.t = (** post-process the raw result of a function call *) -let exe_call_postprocess tenv ret_id trace_call caller_pname callee_pname callee_attrs loc results = +let exe_call_postprocess tenv ret_id trace_call callee_pname callee_attrs loc results = let filter_valid_res = function Invalid_res _ -> false | Valid_res _ -> true in let valid_res0, invalid_res0 = List.partition_tf ~f:filter_valid_res results in let valid_res = @@ -1392,10 +1392,6 @@ let exe_call_postprocess tenv ret_id trace_call caller_pname callee_pname callee List.iter ~f:print_pi (List.map ~f:fst cover) ; List.concat_map ~f:snd cover ) in - if !Config.footprint then - List.iter - ~f:(fun (prop, _) -> RetainCycles.report_cycle tenv caller_pname prop) - res_with_path_idents ; trace_call CR_success ; let res = List.map @@ -1446,5 +1442,4 @@ let exe_function_call exe_env callee_summary tenv ret_id_opt caller_pdesc callee actual_params formal_params in let results = List.map ~f:exe_one_spec spec_list in - exe_call_postprocess tenv ret_id_opt trace_call caller_pname callee_pname callee_attrs loc - results + exe_call_postprocess tenv ret_id_opt trace_call callee_pname callee_attrs loc results diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index 2f44cafba..db6dd62aa 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -2,7 +2,7 @@ codetoanalyze/objc/errors/field_superclass/field.c, field_superclass_main, 3, RE codetoanalyze/objc/errors/global_const/global_const.m, SimpleRoot_doSomethingBadWithDict:andString:, 3, NULL_DEREFERENCE, ERROR, [start of procedure doSomethingBadWithDict:andString:,Message stringByAppendingString: with receiver nil returns nil.] codetoanalyze/objc/errors/global_const/global_const.m, SimpleRoot_doSomethingOkWithDict:andString:, 3, NULL_DEREFERENCE, ERROR, [start of procedure doSomethingOkWithDict:andString:,Message stringByAppendingString: with receiver nil returns nil.] codetoanalyze/objc/errors/initialization/compound_literal.c, init_with_compound_literal, 2, DIVIDE_BY_ZERO, ERROR, [start of procedure init_with_compound_literal()] -codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleStaticVar.m, RetainCSV_foo, 13, RETAIN_CYCLE, ERROR, [start of procedure foo] +codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleStaticVar.m, RetainCSV_foo, 13, RETAIN_CYCLE, ERROR, [start of procedure foo,Executing synthesized setter setHandler:] codetoanalyze/objc/errors/npe/null_returned_by_method.m, NullReturnedByMethodA_test1, 1, NULL_DEREFERENCE, ERROR, [start of procedure test1,start of procedure test,return from a call to NullReturnedByMethodA_test] codetoanalyze/objc/errors/procdescs/main.c, ProcdescMain, 3, MEMORY_LEAK, ERROR, [start of procedure ProcdescMain(),Skipping plusX:andY:: function or method not found] codetoanalyze/objc/errors/procdescs/main.c, call_nslog, 3, MEMORY_LEAK, ERROR, [start of procedure call_nslog(),Skipping NSLog(): function or method not found] @@ -29,13 +29,13 @@ codetoanalyze/objc/errors/initialization/struct_initlistexpr.c, field_set_correc codetoanalyze/objc/errors/initialization/struct_initlistexpr.c, implicit_expr_set_correctly, 3, DIVIDE_BY_ZERO, ERROR, [start of procedure implicit_expr_set_correctly()] codetoanalyze/objc/errors/initialization/struct_initlistexpr.c, point_coords_set_correctly, 2, DIVIDE_BY_ZERO, ERROR, [start of procedure point_coords_set_correctly()] codetoanalyze/objc/errors/memory_leaks_benchmark/CADisplayLinkRetainCycle.m, CADisplay_init, 1, RETAIN_CYCLE, ERROR, [start of procedure init] -codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleBlockCapturedVar.m, LinkResolver_test_bad, 3, RETAIN_CYCLE, ERROR, [start of procedure test_bad] -codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleBlocks.m, RCBlock_retain_self_in_block, 1, RETAIN_CYCLE, ERROR, [start of procedure retain_self_in_block] -codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleBlocks.m, objc_blockretain_a_in_block_cycle_3, 1, RETAIN_CYCLE, ERROR, [start of procedure block] -codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleBlocks.m, retain_a_in_block_cycle, 4, RETAIN_CYCLE, ERROR, [start of procedure retain_a_in_block_cycle(),Executing synthesized setter setB:] -codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCyclePropertyInProtocol.m, MyCustomViewController_loadViewBad, 3, RETAIN_CYCLE, ERROR, [start of procedure loadViewBad,Executing synthesized setter setView:] -codetoanalyze/objc/errors/memory_leaks_benchmark/retain_cycle.m, strongcycle, 6, RETAIN_CYCLE, ERROR, [start of procedure strongcycle(),Executing synthesized setter setB:] -codetoanalyze/objc/errors/memory_leaks_benchmark/retain_cycle2.m, strongcycle2, 4, RETAIN_CYCLE, ERROR, [start of procedure strongcycle2(),start of procedure init,return from a call to Parent_init,start of procedure init,return from a call to Child_init,start of procedure setChild:,return from a call to Parent_setChild:] +codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleBlockCapturedVar.m, LinkResolver_test_bad, 3, RETAIN_CYCLE, ERROR, [start of procedure test_bad,Executing synthesized setter setDidFinishLoad:] +codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleBlocks.m, RCBlock_retain_self_in_block, 1, RETAIN_CYCLE, ERROR, [start of procedure retain_self_in_block,Executing synthesized setter setHandler:] +codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleBlocks.m, objc_blockretain_a_in_block_cycle_3, 1, RETAIN_CYCLE, ERROR, [start of procedure block,Executing synthesized setter setChild:] +codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleBlocks.m, retain_a_in_block_cycle, 4, RETAIN_CYCLE, ERROR, [start of procedure retain_a_in_block_cycle(),Executing synthesized setter setB:,Executing synthesized setter setA:] +codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCyclePropertyInProtocol.m, MyCustomViewController_loadViewBad, 3, RETAIN_CYCLE, ERROR, [start of procedure loadViewBad,Executing synthesized setter setView:,Executing synthesized setter setStrong_delegate:] +codetoanalyze/objc/errors/memory_leaks_benchmark/retain_cycle.m, strongcycle, 6, RETAIN_CYCLE, ERROR, [start of procedure strongcycle(),Executing synthesized setter setB:,Executing synthesized setter setA:] +codetoanalyze/objc/errors/memory_leaks_benchmark/retain_cycle2.m, strongcycle2, 4, RETAIN_CYCLE, ERROR, [start of procedure strongcycle2(),start of procedure init,return from a call to Parent_init,start of procedure init,return from a call to Child_init,start of procedure setChild:,return from a call to Parent_setChild:,start of procedure setParent:,return from a call to Child_setParent:] codetoanalyze/objc/errors/npe/UpdateDict.m, add_nil_in_dict, 10, NULL_DEREFERENCE, ERROR, [start of procedure add_nil_in_dict(),Skipping dictionaryWithObjectsAndKeys:: function or method not found] codetoanalyze/objc/errors/npe/UpdateDict.m, add_nil_to_array, 4, NULL_DEREFERENCE, ERROR, [start of procedure add_nil_to_array()] codetoanalyze/objc/errors/npe/UpdateDict.m, insert_nil_in_array, 4, NULL_DEREFERENCE, ERROR, [start of procedure insert_nil_in_array()] @@ -73,7 +73,7 @@ codetoanalyze/objc/errors/variadic_methods/premature_nil_termination.m, Prematur codetoanalyze/objc/errors/memory_leaks_benchmark/CoreVideoExample.m, CoreVideoExample_cvpixelbuffer_not_released_leak, 1, MEMORY_LEAK, ERROR, [start of procedure cvpixelbuffer_not_released_leak] codetoanalyze/objc/errors/memory_leaks_benchmark/NSData_models_tests.m, NSData_models_tests_macForIV:, 2, MEMORY_LEAK, ERROR, [start of procedure macForIV:] codetoanalyze/objc/errors/memory_leaks_benchmark/NSString_models_tests.m, StringInitA_hexStringValue, 11, MEMORY_LEAK, ERROR, [start of procedure hexStringValue,Skipping CFStringCreateWithBytesNoCopy(): function or method not found,Condition is false] -codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleLength3.m, strongcycle, 6, RETAIN_CYCLE, ERROR, [start of procedure strongcycle(),Executing synthesized setter setB:,Executing synthesized setter setC:] +codetoanalyze/objc/errors/memory_leaks_benchmark/RetainCycleLength3.m, strongcycle, 6, RETAIN_CYCLE, ERROR, [start of procedure strongcycle(),Executing synthesized setter setB:,Executing synthesized setter setC:,Executing synthesized setter setA:] codetoanalyze/objc/errors/npe/Fraction.m, test_virtual_call, 7, NULL_DEREFERENCE, ERROR, [start of procedure test_virtual_call(),start of procedure setNumerator:,return from a call to Fraction_setNumerator:,start of procedure getNumerator,return from a call to Fraction_getNumerator,Condition is true] codetoanalyze/objc/errors/npe/Npe_with_equal_names.m, EqualNamesTest, 3, NULL_DEREFERENCE, ERROR, [start of procedure EqualNamesTest(),start of procedure meth,return from a call to EqualNamesA_meth] codetoanalyze/objc/errors/npe/block.m, BlockA_doSomethingThenCallback:, 2, PARAMETER_NOT_NULL_CHECKED, WARNING, [start of procedure doSomethingThenCallback:]