From 4e7fc51ad22d17585fb34d6942308fcc4a3f6006 Mon Sep 17 00:00:00 2001 From: Sungkeun Cho Date: Thu, 1 Oct 2020 01:28:50 -0700 Subject: [PATCH] [cost] Add FN tests on enumerator Summary: The problem: current enumerator semantics does not work on symbolic enumerator that is given as a parameter. Reviewed By: ezgicicek Differential Revision: D24017059 fbshipit-source-id: 378e75bb0 --- infer/tests/codetoanalyze/objc/performance/NSArray.m | 11 +++++++++++ .../codetoanalyze/objc/performance/cost-issues.exp | 2 ++ 2 files changed, 13 insertions(+) diff --git a/infer/tests/codetoanalyze/objc/performance/NSArray.m b/infer/tests/codetoanalyze/objc/performance/NSArray.m index d9cc5cbb9..bab92bb2d 100644 --- a/infer/tests/codetoanalyze/objc/performance/NSArray.m +++ b/infer/tests/codetoanalyze/objc/performance/NSArray.m @@ -166,6 +166,17 @@ void nsarray_enumerator_linear(NSArray* array) { } } +void nsarray_enumerator_param_linear_FN(NSEnumerator* enumerator) { + id obj; + while (obj = [enumerator nextObject]) { + } +} + +void call_nsarray_enumerator_param_linear_FN(NSArray* array) { + NSEnumerator* enumerator = [array objectEnumerator]; + nsarray_enumerator_param_linear_FN(enumerator); +} + void nsarray_next_object_linear(NSArray* array) { for (id item in array) { } diff --git a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp index 538e3bdd2..78081e1f1 100644 --- a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp +++ b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp @@ -1,4 +1,5 @@ ${XCODE_ISYSROOT}/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h, NSArray.indexOfObject:inSortedRange:options:usingComparator:[objc_blocknsarray_binary_search_log_FN_1], 0, OnUIThread:false, [] +codetoanalyze/objc/performance/NSArray.m, call_nsarray_enumerator_param_linear_FN, 12, OnUIThread:false, [] codetoanalyze/objc/performance/NSArray.m, nsarray_access_constant, 50, OnUIThread:false, [] codetoanalyze/objc/performance/NSArray.m, nsarray_access_linear, 3 + 7 ⋅ array->elements.length.ub + 3 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop] codetoanalyze/objc/performance/NSArray.m, nsarray_add_object_constant, 8, OnUIThread:false, [] @@ -9,6 +10,7 @@ codetoanalyze/objc/performance/NSArray.m, nsarray_contains_object_linear, 3 + ar codetoanalyze/objc/performance/NSArray.m, nsarray_count_bounded_linear, 3 + 3 ⋅ array->elements.length.ub + 3 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop] codetoanalyze/objc/performance/NSArray.m, nsarray_empty_array_constant, 8, OnUIThread:false, [] codetoanalyze/objc/performance/NSArray.m, nsarray_enumerator_linear, 6 + 4 ⋅ array->elements.length.ub + 4 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop] +codetoanalyze/objc/performance/NSArray.m, nsarray_enumerator_param_linear_FN, 7, OnUIThread:false, [] codetoanalyze/objc/performance/NSArray.m, nsarray_find_linear, 4 + 9 ⋅ array->elements.length.ub + 3 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop] codetoanalyze/objc/performance/NSArray.m, nsarray_first_object_constant, 4, OnUIThread:false, [] codetoanalyze/objc/performance/NSArray.m, nsarray_get_first_constant, 27, OnUIThread:false, []