diff --git a/infer/src/IR/CapturedVar.ml b/infer/src/IR/CapturedVar.ml index 7039bf316..26125f6e3 100644 --- a/infer/src/IR/CapturedVar.ml +++ b/infer/src/IR/CapturedVar.ml @@ -8,8 +8,8 @@ open! IStd module F = Format -type t = {name: Pvar.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] +type t = {name: Mangled.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] let pp fmt {name; typ; capture_mode} = - F.fprintf fmt "(%a,@,%a,@,%s)" (Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ + F.fprintf fmt "(%a,@,%a,@,%s)" Mangled.pp name (Typ.pp_full Pp.text) typ (Pvar.string_of_capture_mode capture_mode) diff --git a/infer/src/IR/CapturedVar.mli b/infer/src/IR/CapturedVar.mli index dea404e68..0603bcb0d 100644 --- a/infer/src/IR/CapturedVar.mli +++ b/infer/src/IR/CapturedVar.mli @@ -7,6 +7,6 @@ open! IStd -type t = {name: Pvar.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] +type t = {name: Mangled.t; typ: Typ.t; capture_mode: Pvar.capture_mode} [@@deriving compare] val pp : Format.formatter -> t -> unit diff --git a/infer/src/IR/DotCfg.ml b/infer/src/IR/DotCfg.ml index 8a38b6837..2118c0868 100644 --- a/infer/src/IR/DotCfg.ml +++ b/infer/src/IR/DotCfg.ml @@ -24,7 +24,7 @@ let pp_var_list fmt etl = List.iter etl ~f:(fun {CapturedVar.name; typ; capture_mode} -> Format.fprintf fmt " [%s]%a:%a" (Pvar.string_of_capture_mode capture_mode) - (Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ ) + Mangled.pp name (Typ.pp_full Pp.text) typ ) let pp_local_list fmt etl = List.iter ~f:(Procdesc.pp_local fmt) etl diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index e34703876..07f6735a8 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -792,7 +792,7 @@ let pp_captured_list fmt etl = ~f:(fun {CapturedVar.name; typ; capture_mode} -> Format.fprintf fmt " [%s] %a:%a" (Pvar.string_of_capture_mode capture_mode) - (Pvar.pp Pp.text) name (Typ.pp_full Pp.text) typ ) + Mangled.pp name (Typ.pp_full Pp.text) typ ) etl @@ -847,7 +847,7 @@ let is_captured_pvar procdesc pvar = | _ -> false in - let pvar_matches_in_captured {CapturedVar.name} = Pvar.equal name pvar in + let pvar_matches_in_captured {CapturedVar.name} = Mangled.equal name pvar_name in let is_captured_var_objc_block = (* var is captured if the procedure is a objc block and the var is in the captured *) Procname.is_objc_block procname diff --git a/infer/src/biabduction/Rearrange.ml b/infer/src/biabduction/Rearrange.ml index 324f273f7..9b2a4fcc5 100644 --- a/infer/src/biabduction/Rearrange.ml +++ b/infer/src/biabduction/Rearrange.ml @@ -1288,8 +1288,9 @@ let check_call_to_objc_block_error tenv pdesc prop fun_exp loc = match get_exp_called () with | Some (_, Exp.Lvar pvar) -> (* pvar is the block *) + let name = Pvar.get_name pvar in List.exists - ~f:(fun {CapturedVar.name= cn} -> Pvar.equal pvar cn) + ~f:(fun {CapturedVar.name= cn} -> Mangled.equal name cn) (Procdesc.get_captured pdesc) | _ -> false diff --git a/infer/src/checkers/SelfInBlock.ml b/infer/src/checkers/SelfInBlock.ml index 7ba53bd55..f7eac8536 100644 --- a/infer/src/checkers/SelfInBlock.ml +++ b/infer/src/checkers/SelfInBlock.ml @@ -148,10 +148,11 @@ module TransferFunctions = struct let pp_session_name _node fmt = F.pp_print_string fmt "SelfCapturedInBlock" let is_captured_self attributes pvar = + let pvar_name = Pvar.get_name pvar in Pvar.is_self pvar && List.exists ~f:(fun {CapturedVar.name= captured; typ} -> - Pvar.equal captured pvar && Typ.is_strong_pointer typ ) + Mangled.equal captured pvar_name && Typ.is_strong_pointer typ ) attributes.ProcAttributes.captured @@ -160,16 +161,17 @@ module TransferFunctions = struct (not (Pvar.is_self pvar)) && List.exists ~f:(fun {CapturedVar.name= captured; typ} -> - Typ.is_strong_pointer typ && Pvar.equal captured pvar - && String.is_suffix ~suffix:"self" (String.lowercase (Pvar.to_string captured)) ) + Typ.is_strong_pointer typ + && Mangled.equal captured (Pvar.get_name pvar) + && String.is_suffix ~suffix:"self" (String.lowercase (Mangled.to_string captured)) ) attributes.ProcAttributes.captured let is_captured_weak_self attributes pvar = List.exists ~f:(fun {CapturedVar.name= captured; typ} -> - Pvar.equal captured pvar - && String.is_substring ~substring:"self" (String.lowercase (Pvar.to_string captured)) + Mangled.equal captured (Pvar.get_name pvar) + && String.is_substring ~substring:"self" (String.lowercase (Mangled.to_string captured)) && Typ.is_weak_pointer typ ) attributes.ProcAttributes.captured diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index d967cc4a9..e7fc86297 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -207,7 +207,7 @@ let create_local_procdesc ?(set_objc_accessor_attr = false) ?(record_lambda_capt in let captured_mangled = List.map - ~f:(fun (var, typ, capture_mode) -> {CapturedVar.name= var; typ; capture_mode}) + ~f:(fun (var, typ, capture_mode) -> {CapturedVar.name= Pvar.get_name var; typ; capture_mode}) captured in (* Retrieve captured variables from procdesc created when translating captured variables in lambda expression *) @@ -235,7 +235,7 @@ let create_local_procdesc ?(set_objc_accessor_attr = false) ?(record_lambda_capt (* Captured variables for blocks are treated as parameters, but not for cpp lambdas *) let captured_as_formals = if is_cpp_lambda_call_operator then [] - else List.map ~f:(fun {CapturedVar.name; typ} -> (Pvar.get_name name, typ)) captured_mangled + else List.map ~f:(fun {CapturedVar.name; typ} -> (name, typ)) captured_mangled in let formals = captured_as_formals @ formals in let const_formals = diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 2adf6cbbe..29e4d44bf 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -828,8 +828,9 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let typ = match procname with | Procname.ObjC_Cpp cpp_pname when Procname.ObjC_Cpp.is_cpp_lambda cpp_pname -> + let pvar_name = Pvar.get_name pvar in List.find (Procdesc.get_captured context.procdesc) - ~f:(fun {CapturedVar.name= captured_var} -> Pvar.equal captured_var pvar) + ~f:(fun {CapturedVar.name= captured_var} -> Mangled.equal captured_var pvar_name) |> Option.value_map ~f:(fun {CapturedVar.typ} -> typ) ~default:typ | _ -> typ diff --git a/infer/src/pulse/PulseAbductiveDomain.ml b/infer/src/pulse/PulseAbductiveDomain.ml index 8e32f6d65..efb8a24f4 100644 --- a/infer/src/pulse/PulseAbductiveDomain.ml +++ b/infer/src/pulse/PulseAbductiveDomain.ml @@ -305,12 +305,12 @@ let mk_initial proc_desc = let formals_and_captured = let proc_name = Procdesc.get_proc_name proc_desc in let location = Procdesc.get_loc proc_desc in - let init_var pvar = + let init_var mangled = + let pvar = Pvar.mk mangled proc_name in (Var.of_pvar pvar, (AbstractValue.mk_fresh (), [ValueHistory.FormalDeclared (pvar, location)])) in - let init_mangled mangled = init_var (Pvar.mk mangled proc_name) in let formals = - Procdesc.get_formals proc_desc |> List.map ~f:(fun (mangled, _) -> init_mangled mangled) + Procdesc.get_formals proc_desc |> List.map ~f:(fun (mangled, _) -> init_var mangled) in let captured = Procdesc.get_captured proc_desc |> List.map ~f:(fun {CapturedVar.name} -> init_var name) diff --git a/infer/src/pulse/PulseOperations.ml b/infer/src/pulse/PulseOperations.ml index e96bb8fe3..f29a1188d 100644 --- a/infer/src/pulse/PulseOperations.ml +++ b/infer/src/pulse/PulseOperations.ml @@ -520,7 +520,9 @@ let call ~caller_proc_desc err_log ~(callee_data : (Procdesc.t * PulseSummary.t) in let captured_vars = Procdesc.get_captured callee_proc_desc - |> List.map ~f:(fun {CapturedVar.name; capture_mode} -> (Var.of_pvar name, capture_mode)) + |> List.map ~f:(fun {CapturedVar.name; capture_mode} -> + let pvar = Pvar.mk name callee_pname in + (Var.of_pvar pvar, capture_mode) ) in let+ astate, captured_vars_with_actuals = match actuals with