From ddc354df395e0143a6c8841dfc9e741cceaf3336 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Tue, 27 Feb 2018 08:07:28 -0800 Subject: [PATCH] [IR] utility function for detecting when Var appears in source code Summary: We frequently want to treat such vars differently than true program variables. Used in only one place now, but will be used in a successor. Reviewed By: mbouaziz, jvillard Differential Revision: D7067882 fbshipit-source-id: 90e0348 --- infer/src/absint/Var.ml | 6 ++++++ infer/src/absint/Var.mli | 4 ++++ infer/src/concurrency/RacerD.ml | 8 ++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/infer/src/absint/Var.ml b/infer/src/absint/Var.ml index 69432f056..1e51fd9b7 100644 --- a/infer/src/absint/Var.ml +++ b/infer/src/absint/Var.ml @@ -29,6 +29,12 @@ let is_return = function ProgramVar pvar -> Pvar.is_return pvar | LogicalVar _ - let is_footprint = function ProgramVar _ -> false | LogicalVar id -> Ident.is_footprint id +let appears_in_source_code = function + | LogicalVar _ -> + false + | ProgramVar pvar -> + not (Pvar.is_frontend_tmp pvar) + let pp fmt = function ProgramVar pv -> Pvar.pp Pp.text fmt pv | LogicalVar id -> Ident.pp fmt id let get_footprint_index t = diff --git a/infer/src/absint/Var.mli b/infer/src/absint/Var.mli index 5fc33c581..f52fbc492 100644 --- a/infer/src/absint/Var.mli +++ b/infer/src/absint/Var.mli @@ -30,6 +30,10 @@ val is_return : t -> bool val is_footprint : t -> bool +val appears_in_source_code : t -> bool +(** return true if this variable appears in source code (i.e., is not a LogicalVar or a + frontend-generated ProgramVar) *) + val get_footprint_index : t -> int option val pp : Format.formatter -> t -> unit diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index 8294b096b..6b98cd7af 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -1014,12 +1014,8 @@ let report_thread_safety_violation tenv pdesc ~make_description ~report_kind acc let is_full_trace = TraceElem.is_direct final_sink in let is_pvar_base initial_sink = let access_path = Access.get_access_path (PathDomain.Sink.kind initial_sink) in - Option.value_map ~default:false access_path ~f:(fun ap -> - match ap with - | (Var.LogicalVar _, _), _ -> - false - | (Var.ProgramVar pvar, _), _ -> - not (Pvar.is_frontend_tmp pvar) ) + Option.value_map ~default:false access_path ~f:(fun ((var, _), _) -> + Var.appears_in_source_code var ) in (* Traces can be truncated due to limitations of our Buck integration. If we have a truncated trace, it's probably going to be too confusing to be actionable. Skip it.