From dcc12d0a42b9bb43a4ca4daef4dd9433e3567d3b Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Tue, 18 Aug 2020 05:01:39 -0700 Subject: [PATCH] [closuressubstitution] Flip order of captured variables and actual parameters Summary: In the frontend captured variables for blocks are added as formal parameters in procdesc at the beginning. Reviewed By: dulmarod Differential Revision: D23163619 fbshipit-source-id: 2bcbe9b9c --- infer/src/backend/ClosuresSubstitution.ml | 2 +- .../tests/codetoanalyze/objc/pulse/MemoryLeaksInBlocks.m | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/infer/src/backend/ClosuresSubstitution.ml b/infer/src/backend/ClosuresSubstitution.ml index 93da6e18a..f37da21c4 100644 --- a/infer/src/backend/ClosuresSubstitution.ml +++ b/infer/src/backend/ClosuresSubstitution.ml @@ -100,7 +100,7 @@ let replace_instr node (astate : Domain.t) (instr : Sil.instr) : Sil.instr = let captured_values = List.map ~f:(fun (id_exp, _, typ, _) -> (id_exp, typ)) c.captured_vars in - let actual_params = actual_params @ captured_values in + let actual_params = captured_values @ actual_params in let new_instr = Sil.Call (ret_id_typ, Const (Cfun c.name), actual_params, loc, call_flags) in diff --git a/infer/tests/codetoanalyze/objc/pulse/MemoryLeaksInBlocks.m b/infer/tests/codetoanalyze/objc/pulse/MemoryLeaksInBlocks.m index 1bd6025bc..036b4a32c 100644 --- a/infer/tests/codetoanalyze/objc/pulse/MemoryLeaksInBlocks.m +++ b/infer/tests/codetoanalyze/objc/pulse/MemoryLeaksInBlocks.m @@ -17,13 +17,13 @@ int block_captured_var_leak_bad() { return blk(); } -int block_free_ok() { +int block_free_ok(int* y) { int* x = malloc(sizeof(int)); *x = 2; - int (^blk)(void) = ^() { - int i = *x; + int (^blk)(int*) = ^(int* y) { + int i = *x + *y; free(x); return i; }; - return blk(); + return blk(y); }