Skip to content

Commit

Permalink
[self-in-block] Do not report strongSelf Not Checked when the variabl…
Browse files Browse the repository at this point in the history
…e is the receiver of an instance method call

Summary: If `strongSelf` is nil in these situations there won't be a crash.

Reviewed By: ngorogiannis

Differential Revision: D65942642

fbshipit-source-id: 82e649fb17b7b0329620b041bd00e8a49132515a
  • Loading branch information
dulmarod authored and facebook-github-bot committed Nov 14, 2024
1 parent 060b3dd commit 08b7b53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 8 additions & 1 deletion infer/src/checkers/SelfInBlock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,14 @@ module TransferFunctions = struct
| Prune (UnOp (LNot, BinOp (Binop.Ne, Var id, e), _), _, _, _)
when Exp.is_null_literal e (* if !(strongSef != nil) *) ->
Domain.clear_unchecked_use id astate
| Call (_, Exp.Const (Const.Cfun _callee_pn), args, _, _) ->
| Call (_, Exp.Const (Const.Cfun _callee_pn), args, _, cf) ->
let fst = if cf.CallFlags.cf_virtual then List.hd args else None in
let astate =
Option.value_map
~f:(fun (arg, _) ->
match arg with Exp.Var id -> Domain.clear_unchecked_use id astate | _ -> astate )
~default:astate fst
in
List.fold ~init:astate ~f:(fun astate (exp, _) -> Domain.process_exp exp astate) args
| _ ->
astate
Expand Down
1 change: 0 additions & 1 deletion infer/tests/codetoanalyze/objc/self-in-block/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ codetoanalyze/objc/self-in-block/SelfInBlockPassedToInit.m, objc_block_SelfInBlo
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:65, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self,Using &self], "self"=>"strongSelf"@69:15
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:65, 5, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self,Using &self], "self"=>"strongSelf"@70:8
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:78, 1, CAPTURED_STRONG_SELF, no_bucket, ERROR, [Using captured &weakSelf]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:86, 2, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [Using &strongSelf]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:97, 2, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [Using &strongSelf]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:106, 6, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [Using &strongSelf,Using &strongSelf,Using &strongSelf,Using &strongSelf], +""=>"\n if (!strongSelf) { return; }"@108:1
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:121, 6, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [Using &strongSelf,Using &strongSelf,Using &strongSelf]
Expand Down

0 comments on commit 08b7b53

Please sign in to comment.