[inferbo] Add model for NSDictionary.initWithDictionary

Summary: Model it similar to `NSArray.initWithArray` as copying from the given dictionary elements. Removes a FP as expected.

Reviewed By: ngorogiannis

Differential Revision: D24136868

fbshipit-source-id: ed31c3c8f
master
Ezgi Çiçek 5 years ago committed by Facebook GitHub Bot
parent 4a1c513d4e
commit ec88edd564

@ -1518,6 +1518,9 @@ let objc_malloc exp =
match exp with
| Exp.Sizeof {typ} when PatternMatch.ObjectiveC.implements "NSArray" tenv (Typ.to_string typ) ->
NSCollection.new_collection.exec model ~ret mem
| Exp.Sizeof {typ}
when PatternMatch.ObjectiveC.implements "NSDictionary" tenv (Typ.to_string typ) ->
NSCollection.new_collection.exec model ~ret mem
| Exp.Sizeof {typ} when PatternMatch.ObjectiveC.implements "NSString" tenv (Typ.to_string typ)
->
(NSString.create_with_c_string (Exp.Const (Const.Cstr ""))).exec model ~ret mem
@ -1679,6 +1682,8 @@ module Call = struct
; +PatternMatch.ObjectiveC.implements "NSArray" &:: "array" <>--> NSCollection.new_collection
; +PatternMatch.ObjectiveC.implements "NSArray"
&:: "firstObject" <>$ capt_var_exn $!--> NSCollection.get_first
; +PatternMatch.ObjectiveC.implements "NSDictionary"
&:: "initWithDictionary:" <>$ capt_var_exn $+ capt_exp $--> NSCollection.copy
; +PatternMatch.ObjectiveC.implements "NSArray"
&:: "initWithArray:" <>$ capt_var_exn $+ capt_exp $--> NSCollection.copy
; +PatternMatch.ObjectiveC.implements "NSArray"

@ -19,7 +19,7 @@ NSDictionary* nsdictionary_init_dictionary_constant() {
return [NSDictionary dictionary];
}
void nsdictionary_init_with_dictionary_linear_FP(NSDictionary* dict) {
void nsdictionary_init_with_dictionary_linear(NSDictionary* dict) {
NSDictionary* copy_dict = [[NSDictionary alloc] initWithDictionary:dict];
for (int i = 0; i < [copy_dict allValues].count; i++) {
}

@ -40,7 +40,7 @@ codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_fast_enumerate_linea
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_find_key_constant, 19, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_dictionary_constant, 3, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_literal_constant, 45, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, , OnUIThread:false, [Unbounded loop,Loop]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear, 7 + 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/NSInteger.m, nsinteger_value_linear, 3 + 3 ⋅ integer + 2 ⋅ (1+max(0, integer)), OnUIThread:false, [{1+max(0, integer)},Loop,{integer},Loop]
codetoanalyze/objc/performance/NSInteger.m, nsnumber_number_with_int_integer_value_constant, 34, OnUIThread:false, []
codetoanalyze/objc/performance/NSMutableArray.m, nsarray_new_constant, 9, OnUIThread:false, []

@ -1,7 +1,5 @@
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_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, [<LHS trace>,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]
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_remove_constant, 6, BUFFER_OVERRUN_L1, no_bucket, ERROR, [<Length trace>,Array declaration,Through,Through,Through,Through,Array access: Offset: 0 Size: 0]
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_remove_in_loop_constant, 6, BUFFER_OVERRUN_L3, no_bucket, ERROR, [<Offset trace>,Set array size,<Length trace>,Assignment,Set array size,Array access: Offset: [0, 9] Size: [1, 10]]

Loading…
Cancel
Save