From ebcfae388a0cad4bd2bd8633a5e39327e0240e7b Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Thu, 5 May 2016 10:01:31 -0700 Subject: [PATCH] handling Set(Var, _,) as read of var in liveness analysis Reviewed By: jvillard Differential Revision: D3264597 fb-gh-sync-id: efe1982 fbshipit-source-id: efe1982 --- infer/src/checkers/liveness.ml | 3 +-- infer/src/unit/livenessTests.ml | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/infer/src/checkers/liveness.ml b/infer/src/checkers/liveness.ml index a006d7277..7b11295e7 100644 --- a/infer/src/checkers/liveness.ml +++ b/infer/src/checkers/liveness.ml @@ -32,8 +32,7 @@ module TransferFunctions = struct IList.fold_left (fun astate_acc pvar -> Domain.add (ProgramVar pvar) astate_acc) astate' pvars let exec_instr astate _ = function - | Sil.Letderef (lhs_id, rhs_exp, _, _) - | Sil.Set (Sil.Var lhs_id, _, rhs_exp, _) -> + | Sil.Letderef (lhs_id, rhs_exp, _, _) -> Domain.remove (LogicalVar lhs_id) astate |> exp_add_live rhs_exp | Sil.Set (Lvar lhs_pvar, _, rhs_exp, _) -> diff --git a/infer/src/unit/livenessTests.ml b/infer/src/unit/livenessTests.ml index 080049112..6793ac05a 100644 --- a/infer/src/unit/livenessTests.ml +++ b/infer/src/unit/livenessTests.ml @@ -30,6 +30,11 @@ let tests = let unknown_cond = (* don't want to use AnalyzerTest.unknown_exp because we'll treat it as a live var! *) Sil.exp_zero in + let id_set_id lhs_id rhs_id = + let lhs_exp = Sil.Var (ident_of_str lhs_id) in + let rhs_exp = Sil.Var (ident_of_str rhs_id) in + let rhs_typ = dummy_typ in + make_set ~rhs_typ ~lhs_exp ~rhs_exp in let test_list = [ "basic_live", [ @@ -73,6 +78,11 @@ let tests = invariant "{ y$0 }"; id_assign_id "x" "y" ]; + "set_id", + [ + invariant "{ x$0, y$0 }"; + id_set_id "x" "y" (* this is *x = y, which is a read of both x and y *) + ]; "if_exp_live", [ assert_empty;