From f02f7b379e4dae8b602c22c669bd6c401de01cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Wed, 26 Aug 2020 09:08:55 -0700 Subject: [PATCH] [cost] Add FN test for functions that take blocks as arguments Reviewed By: skcho Differential Revision: D23345830 fbshipit-source-id: 9c5b1e0c8 --- .../codetoanalyze/objc/performance/block.m | 21 +++++++++++++++++++ .../objc/performance/cost-issues.exp | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/infer/tests/codetoanalyze/objc/performance/block.m b/infer/tests/codetoanalyze/objc/performance/block.m index b9b529465..6582172b1 100644 --- a/infer/tests/codetoanalyze/objc/performance/block.m +++ b/infer/tests/codetoanalyze/objc/performance/block.m @@ -17,3 +17,24 @@ NSInteger block_multiply_array_linear(NSArray* array) { return sum_array(array); } + +typedef void (^BlockA)(void); +void loop_linear(int x) { + for (int i = 0; i < x; i++) { + } +} + +void runBlockA(BlockA block) { block(); } + +void doBlockA_linear_FN(int a) { + BlockA block = ^{ + loop_linear(a); + }; + runBlockA(block); +} + +void doBlockA_direct_block_linear_FN(int a) { + runBlockA(^{ + loop_linear(a); + }); +} diff --git a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp index 04f293815..f63c87653 100644 --- a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp +++ b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp @@ -79,7 +79,13 @@ codetoanalyze/objc/performance/araii.m, Araii.initWithBuffer, 15, OnUIThread:fa codetoanalyze/objc/performance/araii.m, Araii.setBuffer:, 4, OnUIThread:false, [] codetoanalyze/objc/performance/araii.m, memory_leak_raii_main, 18, OnUIThread:false, [] codetoanalyze/objc/performance/block.m, block_multiply_array_linear, 13 + 5 ⋅ array->elements.length.ub + 4 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Call to objc_blockblock_multiply_array_linear_1,Loop,{array->elements.length.ub},Call to objc_blockblock_multiply_array_linear_1,Loop] +codetoanalyze/objc/performance/block.m, doBlockA_direct_block_linear_FN, 5, OnUIThread:false, [] +codetoanalyze/objc/performance/block.m, doBlockA_linear_FN, 7, OnUIThread:false, [] +codetoanalyze/objc/performance/block.m, loop_linear, 3 + 3 ⋅ x + 2 ⋅ (1+max(0, x)), OnUIThread:false, [{1+max(0, x)},Loop,{x},Loop] codetoanalyze/objc/performance/block.m, objc_blockblock_multiply_array_linear_1, 8 + 5 ⋅ 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/block.m, objc_blockdoBlockA_direct_block_linear_FN_3, 5 + 3 ⋅ a + 2 ⋅ (1+max(0, a)), OnUIThread:false, [{1+max(0, a)},Call to loop_linear,Loop,{a},Call to loop_linear,Loop] +codetoanalyze/objc/performance/block.m, objc_blockdoBlockA_linear_FN_2, 5 + 3 ⋅ a + 2 ⋅ (1+max(0, a)), OnUIThread:false, [{1+max(0, a)},Call to loop_linear,Loop,{a},Call to loop_linear,Loop] +codetoanalyze/objc/performance/block.m, runBlockA, 3, OnUIThread:false, [] codetoanalyze/objc/performance/break.m, break_constant_FP, 8 + 5 ⋅ p + 2 ⋅ (1+max(0, p)), OnUIThread:false, [{1+max(0, p)},Call to break_loop,Loop,{p},Call to break_loop,Loop] codetoanalyze/objc/performance/break.m, break_loop, 5 + 5 ⋅ p + 2 ⋅ (1+max(0, p)), OnUIThread:false, [{1+max(0, p)},Loop,{p},Loop] codetoanalyze/objc/performance/break.m, break_loop_with_t, 7 + 5 ⋅ p + 2 ⋅ (1+max(0, p)), OnUIThread:false, [{1+max(0, p)},Loop,{p},Loop]