From 9cce84ac6cd17a8b3eb810a37cc1065c6c83b438 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Mon, 4 Feb 2019 02:08:13 -0800 Subject: [PATCH] dont report biabduction NPE's on tmp variables Reviewed By: da319 Differential Revision: D13800608 fbshipit-source-id: 2f54c8be6 --- infer/src/IR/DecompiledExp.ml | 2 +- infer/src/IR/Pvar.ml | 4 ++++ infer/src/IR/Pvar.mli | 3 +++ infer/src/biabduction/Buckets.ml | 7 ++++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/infer/src/IR/DecompiledExp.ml b/infer/src/IR/DecompiledExp.ml index be5e092b0..8bec31c0c 100644 --- a/infer/src/IR/DecompiledExp.ml +++ b/infer/src/IR/DecompiledExp.ml @@ -147,7 +147,7 @@ let pp_vpath pe fmt vpath = let rec has_tmp_var = function | Dpvar pvar | Dpvaraddr pvar -> - Pvar.is_frontend_tmp pvar + Pvar.is_frontend_tmp pvar || Pvar.is_clang_tmp pvar | Dderef dexp | Ddot (dexp, _) | Darrow (dexp, _) | Dunop (_, dexp) | Dsizeof (_, Some dexp, _) -> has_tmp_var dexp diff --git a/infer/src/IR/Pvar.ml b/infer/src/IR/Pvar.ml index 5fd0e293e..aa64246c0 100644 --- a/infer/src/IR/Pvar.ml +++ b/infer/src/IR/Pvar.ml @@ -171,6 +171,10 @@ let is_frontend_tmp pvar = false +let tmp_clang_regex = Str.regexp "^__\\(range\\|begin\\|end\\)[0-9]*$" + +let is_clang_tmp pvar = Str.string_match tmp_clang_regex (to_string pvar) 0 + (* in Sawja, variables like $T0_18 are temporaries, but not SSA vars. *) let is_ssa_frontend_tmp pvar = is_frontend_tmp pvar diff --git a/infer/src/IR/Pvar.mli b/infer/src/IR/Pvar.mli index fdd04ad8c..e8c957327 100644 --- a/infer/src/IR/Pvar.mli +++ b/infer/src/IR/Pvar.mli @@ -72,6 +72,9 @@ val is_self : t -> bool val is_frontend_tmp : t -> bool (** return true if [pvar] is a temporary variable generated by the frontend *) +val is_clang_tmp : t -> bool +(** return true if [pvar] is a temporary variable generated by clang *) + val is_ssa_frontend_tmp : t -> bool (** return true if [pvar] is a temporary variable generated by the frontend and is only assigned once on a non-looping control-flow path *) diff --git a/infer/src/biabduction/Buckets.ml b/infer/src/biabduction/Buckets.ml index 5410a0159..d9b7d3e1a 100644 --- a/infer/src/biabduction/Buckets.ml +++ b/infer/src/biabduction/Buckets.ml @@ -10,6 +10,7 @@ open! IStd (** Classify bugs into buckets *) +module DExp = DecompiledExp module L = Logging let verbose = Config.trace_error @@ -152,5 +153,9 @@ let check_access access_opt de_opt = let classify_access desc access_opt de_opt is_nullable = let default_bucket = if is_nullable then Localise.BucketLevel.b1 else Localise.BucketLevel.b5 in - let bucket = check_access access_opt de_opt |> Option.value ~default:default_bucket in + let tmp_var = Option.value_map de_opt ~default:false ~f:DExp.has_tmp_var in + let bucket = + if tmp_var then Localise.BucketLevel.b5 + else check_access access_opt de_opt |> Option.value ~default:default_bucket + in Localise.error_desc_set_bucket desc bucket