From a07877dcbb8106b6a39fcd37b6470f076e1afcb1 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Tue, 10 Jul 2018 01:02:39 -0700 Subject: [PATCH] Add new Ident.create_fresh function to avoid clashes specialized objc blocks Reviewed By: dulmarod Differential Revision: D8767847 fbshipit-source-id: a731a4a --- infer/src/IR/Ident.ml | 7 +++++++ infer/src/IR/Ident.mli | 3 +++ infer/src/IR/Procdesc.ml | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/infer/src/IR/Ident.ml b/infer/src/IR/Ident.ml index 89a1070e3..67d5e244f 100644 --- a/infer/src/IR/Ident.ml +++ b/infer/src/IR/Ident.ml @@ -180,6 +180,13 @@ let create_normal name stamp = create_with_stamp KNormal name stamp (** Create a fresh identifier with default name for the given kind. *) let create_fresh kind = NameGenerator.create_fresh_ident kind (standard_name kind) +let create_fresh_specialized_with_blocks kind = + let fid = create_fresh kind in + (* The stamps are per-procedure unique, add a big enough number to effectively create + a namespace for vars in objc blocks *) + {fid with stamp= fid.stamp + 10000} + + let create_none () = create_fresh KNone (** Generate a footprint identifier with the given name and stamp *) diff --git a/infer/src/IR/Ident.mli b/infer/src/IR/Ident.mli index cc18dfb92..10ecbee59 100644 --- a/infer/src/IR/Ident.mli +++ b/infer/src/IR/Ident.mli @@ -94,6 +94,9 @@ val update_name_generator : t list -> unit val create_fresh : kind -> t (** Create a fresh identifier with default name for the given kind. *) +val create_fresh_specialized_with_blocks : kind -> t +(** Create a fresh identifier with default name for the given kind, with a non-clashing id for objc block specialization *) + val create_path : string -> t (** Generate a normal identifier whose name encodes a path given as a string. *) diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index b17713d35..887d1bd0a 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -736,7 +736,7 @@ let specialize_with_block_args_instrs resolved_pdesc substitutions = let block_name, extra_formals = Mangled.Map.find block_var substitutions in let ids, id_exp_typs, load_instrs = List.map extra_formals ~f:(fun (var, typ) -> - let id = Ident.create_fresh Ident.knormal in + let id = Ident.create_fresh_specialized_with_blocks Ident.knormal in let pvar = Pvar.mk var resolved_pname in (id, (Exp.Var id, pvar, typ), Sil.Load (id, Exp.Lvar pvar, typ, loc)) ) |> List.unzip3