From aa578ea58679e73e61f4d8108be68f268374525b Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Mon, 9 Apr 2018 05:52:02 -0700 Subject: [PATCH] [retain cycles] Treat missing fields also angelically when it still happens in rare cases Reviewed By: mbouaziz Differential Revision: D7550900 fbshipit-source-id: 11703ab --- infer/src/biabduction/RetainCycles.ml | 21 +++++++++---------- .../codetoanalyze/objc/errors/issues.exp | 1 - 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/infer/src/biabduction/RetainCycles.ml b/infer/src/biabduction/RetainCycles.ml index 04059fcea..372f51ded 100644 --- a/infer/src/biabduction/RetainCycles.ml +++ b/infer/src/biabduction/RetainCycles.ml @@ -65,17 +65,16 @@ let edge_is_strong tenv obj_edge = (* returns items annotation for field fn in struct t *) let get_item_annotation (t: Typ.t) fn = match t.desc with - | Tstruct name - -> ( - let equal_fn (fn', _, _) = Typ.Fieldname.equal fn fn' in - match Tenv.lookup tenv name with - | Some {fields; statics} -> - let find fields = - List.find ~f:equal_fn fields |> Option.value_map ~f:trd3 ~default:[] - in - Some (find fields @ find statics) + | Tstruct name -> ( + match Tenv.lookup tenv name with + | Some {fields} -> ( + match List.find ~f:(fun (fn', _, _) -> Typ.Fieldname.equal fn fn') fields with | None -> - None ) + None + | Some (_, _, ann) -> + Some ann (* Only returns annotations when the type and field are found in the tenv *) ) + | None -> + None ) | _ -> None in @@ -104,7 +103,7 @@ let edge_is_strong tenv obj_edge = ia | None -> true - (* Assume the edge is weak if the type cannot be found in the tenv, to avoid FPs *) + (* Assume the edge is weak if the type or field cannot be found in the tenv, to avoid FPs *) in not (weak_edge_by_type || weak_edge_by_field) diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index acb023d5e..84b0d5b51 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -28,7 +28,6 @@ codetoanalyze/objc/errors/field_superclass/SubtypingExample.m, subtyping_test, 0 codetoanalyze/objc/errors/initialization/struct_initlistexpr.c, field_set_correctly, 2, DIVIDE_BY_ZERO, ERROR, [start of procedure field_set_correctly()] 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,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:]