From b3baf72df8546a6957d264de7b091ebb8714cc46 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Fri, 29 Apr 2016 11:06:51 -0700 Subject: [PATCH] Lazy dinamic dispatch: add missing case where the right hand side is a idenfier Summary: The case where the right hand side of the `Letderef` expression is an identifier was missing. With this diff, the following example is now working as expected: class A { public Object foo() { return new Object(); } } class B extends A { public Object foo() { return null; } } public class Test { static Object bar(A a) { return a.foo(); } static void shoulReport() { B b = new B(); bar(b).toString(); } } using the command: INFER_LAZY_DYNAMIC_DISPATCH=1 infer -- javac Test.java Reviewed By: sblackshear Differential Revision: D3238986 fb-gh-sync-id: d6059fb fbshipit-source-id: d6059fb --- infer/src/IR/cfg.ml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/infer/src/IR/cfg.ml b/infer/src/IR/cfg.ml index 167187ffd..1beb7f5f4 100644 --- a/infer/src/IR/cfg.ml +++ b/infer/src/IR/cfg.ml @@ -692,6 +692,13 @@ module Node = struct (pvar_name, origin_typ) in subst_map := Ident.IdentMap.add id specialized_typ !subst_map; Sil.Letderef (id, convert_exp origin_exp, specialized_typ, loc) :: instrs + | Sil.Letderef (id, (Sil.Var origin_id as origin_exp), origin_typ, loc) -> + let updated_typ = + match Ident.IdentMap.find origin_id !subst_map with + | Sil.Tptr (typ, _) -> typ + | _ -> failwith "Expecting a pointer type" + | exception Not_found -> origin_typ in + Sil.Letderef (id, convert_exp origin_exp, updated_typ, loc) :: instrs | Sil.Letderef (id, origin_exp, origin_typ, loc) -> Sil.Letderef (id, convert_exp origin_exp, origin_typ, loc) :: instrs | Sil.Set (assignee_exp, origin_typ, origin_exp, loc) -> @@ -733,8 +740,8 @@ module Node = struct let loc = get_loc node and kind = convert_node_kind (get_kind node) and instrs = - IList.fold_left convert_instr [] (get_instrs node) in - create cfg loc kind (IList.rev instrs) resolved_proc_desc (get_temps node) + IList.fold_left convert_instr [] (get_instrs node) |> IList.rev in + create cfg loc kind instrs resolved_proc_desc (get_temps node) and loop callee_nodes = match callee_nodes with | [] -> []