diff --git a/infer/src/IR/Pvar.ml b/infer/src/IR/Pvar.ml index 02698d62d..1f97a5f2d 100644 --- a/infer/src/IR/Pvar.ml +++ b/infer/src/IR/Pvar.ml @@ -335,3 +335,7 @@ end) let get_pvar_formals (attributes : ProcAttributes.t) = let pname = attributes.proc_name in List.map attributes.formals ~f:(fun (name, typ) -> (mk name pname, typ)) + + +let is_local_to_procedure proc_name pvar = + get_declaring_function pvar |> Option.exists ~f:(Procname.equal proc_name) diff --git a/infer/src/IR/Pvar.mli b/infer/src/IR/Pvar.mli index b37f68eeb..de818a475 100644 --- a/infer/src/IR/Pvar.mli +++ b/infer/src/IR/Pvar.mli @@ -162,6 +162,8 @@ val is_pod : t -> bool (** Is the variable's type a "Plain Old Data" type (C++)? Always (potentially incorrectly) returns [true] for non-globals. *) +val is_local_to_procedure : Procname.t -> t -> bool + val get_initializer_pname : t -> Procname.t option (** Get the procname of the initializer function for the given global variable *) diff --git a/infer/src/IR/Var.ml b/infer/src/IR/Var.ml index d540a0a2d..f09037cb3 100644 --- a/infer/src/IR/Var.ml +++ b/infer/src/IR/Var.ml @@ -48,15 +48,8 @@ let is_none = function LogicalVar id -> Ident.is_none id | _ -> false let is_this = function ProgramVar pv -> Pvar.is_this pv | LogicalVar _ -> false -let get_declaring_function = function - | LogicalVar _ -> - None - | ProgramVar pvar -> - Pvar.get_declaring_function pvar - - let is_local_to_procedure proc_name var = - get_declaring_function var |> Option.exists ~f:(Procname.equal proc_name) + get_pvar var |> Option.exists ~f:(fun pvar -> Pvar.is_local_to_procedure proc_name pvar) let get_all_vars_in_exp e =