[selfInBlock] Handle conditionals as well as ifs

Summary: We were reporting strongSelf Not Checked when the variable was checked in a conditional, this diff fixes that.

Reviewed By: jvillard

Differential Revision: D19535943

fbshipit-source-id: f8e64e1b7
master
Dulma Churchill 5 years ago committed by Facebook Github Bot
parent e0a4e53426
commit edc47d4a96

@ -305,12 +305,12 @@ module TransferFunctions = struct
with Not_found_s _ | Caml.Not_found -> astate.strongVars
in
{astate with strongVars}
| Prune (Var id, _, _, Sil.Ik_if) ->
| Prune (Var id, _, _, _) ->
exec_null_check_id astate id
(* If (strongSelf != nil) or equivalent else branch *)
| Prune (BinOp (Binop.Ne, Var id, e), _, _, Sil.Ik_if)
| Prune (BinOp (Binop.Ne, Var id, e), _, _, _)
(* If (!(strongSelf == nil)) or equivalent else branch *)
| Prune (UnOp (LNot, BinOp (Binop.Eq, Var id, e), _), _, _, Sil.Ik_if) ->
| Prune (UnOp (LNot, BinOp (Binop.Eq, Var id, e), _), _, _, _) ->
if Exp.is_null_literal e then exec_null_check_id astate id else astate
| Call (_, Exp.Const (Const.Cfun callee_pn), args, _, _) ->
report_unchecked_strongself_issues_on_args astate summary callee_pn args ;

@ -162,6 +162,14 @@ void m2(_Nullable SelfInBlockTest* obj) {}
};
}
- (void)strongSelfCheck6_good {
__weak __typeof(self) weakSelf = self;
int (^my_block)() = ^() {
__strong __typeof(weakSelf) strongSelf = weakSelf;
return strongSelf ? strongSelf->x : 0; // no bug here
};
}
- (void)wekSelfMultiple_bad {
__weak __typeof(self) weakSelf = self;
int (^my_block)(BOOL) = ^(BOOL isTapped) {

@ -3,4 +3,4 @@ codetoanalyze/objc/self-in-block/StrongSelf.m, objc_blockSelfInBlockTest::strong
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_blockSelfInBlockTest::strongSelfCheckOnce_bad_5, 6, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [&strongSelf assigned here,Using &strongSelf not checked for null,Using &strongSelf not checked for null]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_blockSelfInBlockTest::strongSelfCheckOnce_bad_5, 8, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [&strongSelf assigned here,Using &strongSelf not checked for null,Using &strongSelf not checked for null,Using &strongSelf not checked for null,Using &strongSelf not checked for null]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_blockSelfInBlockTest::strongSelfCheckOnce_bad_5, 10, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [&strongSelf assigned here,Using &strongSelf not checked for null,Using &strongSelf not checked for null,Using &strongSelf not checked for null,Using &strongSelf not checked for null,Using &strongSelf not checked for null,Using &strongSelf not checked for null,Using &strongSelf not checked for null]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_blockSelfInBlockTest::wekSelfMultiple_bad_10, 1, MULTIPLE_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &weakSelf]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_blockSelfInBlockTest::wekSelfMultiple_bad_11, 1, MULTIPLE_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &weakSelf]

Loading…
Cancel
Save