From 06489dced05bd0e7d19015c0375721885d6f2c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Fri, 28 Aug 2020 06:27:38 -0700 Subject: [PATCH] [cost] Add FP test for NSDictionary initialization Reviewed By: roro47 Differential Revision: D23396528 fbshipit-source-id: adc1ae05f --- infer/tests/codetoanalyze/objc/performance/NSDictionary.m | 8 ++++++++ .../tests/codetoanalyze/objc/performance/cost-issues.exp | 1 + infer/tests/codetoanalyze/objc/performance/issues.exp | 2 ++ 3 files changed, 11 insertions(+) diff --git a/infer/tests/codetoanalyze/objc/performance/NSDictionary.m b/infer/tests/codetoanalyze/objc/performance/NSDictionary.m index e29d2040e..7f603b9c0 100644 --- a/infer/tests/codetoanalyze/objc/performance/NSDictionary.m +++ b/infer/tests/codetoanalyze/objc/performance/NSDictionary.m @@ -99,3 +99,11 @@ void nsdictionary_enumerator_linear(NSDictionary* dict) { while ((key = [enumerator nextObject])) { } } + +void nsdictionary_enumerate_call_constant_FP() { + NSDictionary* dict = + @{@"helloString" : @"Hello, World!", + @"magicNumber" : @42}; + + nsdictionary_all_values_linear(dict); +} diff --git a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp index a27247741..6b68e5cf4 100644 --- a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp +++ b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp @@ -27,6 +27,7 @@ codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_keys_linear1, 3 codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_keys_linear2, 6 + 3 ⋅ dict->elements.length.ub + 3 ⋅ (dict->elements.length.ub + 1), OnUIThread:false, [{dict->elements.length.ub + 1},Loop,{dict->elements.length.ub},Loop] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_values_linear, 3 + 3 ⋅ dict->elements.length.ub + 4 ⋅ (dict->elements.length.ub + 1), OnUIThread:false, [{dict->elements.length.ub + 1},Loop,{dict->elements.length.ub},Loop] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_dictionary_with_objects_linear, 14 + 15 ⋅ n_entries + 3 ⋅ n_entries + 2 ⋅ (1+max(0, n_entries)) + 4 ⋅ (1+max(0, n_entries)), OnUIThread:false, [{1+max(0, n_entries)},Loop,{1+max(0, n_entries)},Loop,{n_entries},Loop,{n_entries},Loop] +codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerate_call_constant_FP, ⊤, OnUIThread:false, [Unbounded value dict->elements.length.ub,Call to nsdictionary_all_values_linear,Loop] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerate_constant, 52, OnUIThread:false, [] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerator_linear, 5 + dict->elements.length.ub + 4 ⋅ (dict->elements.length.ub + 1), OnUIThread:false, [{dict->elements.length.ub + 1},Loop,{dict->elements.length.ub},Loop] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_fast_enumerate_linear, 5 + dict->elements.length.ub + 4 ⋅ (dict->elements.length.ub + 1), OnUIThread:false, [{dict->elements.length.ub + 1},Loop,{dict->elements.length.ub},Loop] diff --git a/infer/tests/codetoanalyze/objc/performance/issues.exp b/infer/tests/codetoanalyze/objc/performance/issues.exp index edaf12248..0971eebc0 100644 --- a/infer/tests/codetoanalyze/objc/performance/issues.exp +++ b/infer/tests/codetoanalyze/objc/performance/issues.exp @@ -1,5 +1,7 @@ codetoanalyze/objc/performance/NSArray.m, nsarray_empty_array_constant, 3, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here] codetoanalyze/objc/performance/NSArray.m, nsarray_init_constant, 3, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here] +codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerate_call_constant_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded value dict->elements.length.ub,Call to nsdictionary_all_values_linear,Loop] +codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerate_call_constant_FP, 5, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [Unknown value from: NSDictionary.dictionaryWithObjects:forKeys:count:,Call,,Parameter `dict->elements[*]`,Binary operation: ([0, +oo] + 1):signed32 by call to `nsdictionary_all_values_linear` ] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, 2, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [,Unknown value from: NSDictionary.initWithDictionary:,Binary operation: ([0, +oo] + 1):signed32] codetoanalyze/objc/performance/NSMutableArray.m, nsarray_new_constant, 2, CONDITION_ALWAYS_FALSE, no_bucket, WARNING, [Here]