From e3300230cc6a785926caf6b6aeaa14118c0e3c74 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 6 May 2020 11:23:54 -0700 Subject: [PATCH] make InefficientKeysetIterator an `intraprocedural` Summary: Making checkers/ its own dune library. Reviewed By: ezgicicek Differential Revision: D21407063 fbshipit-source-id: 8a3ab3c04 --- infer/src/backend/registerCheckers.ml | 2 +- infer/src/checkers/inefficientKeysetIterator.ml | 14 ++++++-------- infer/src/checkers/inefficientKeysetIterator.mli | 10 ++++++++++ 3 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 infer/src/checkers/inefficientKeysetIterator.mli diff --git a/infer/src/backend/registerCheckers.ml b/infer/src/backend/registerCheckers.ml index cb0e93e6c..675a31db4 100644 --- a/infer/src/backend/registerCheckers.ml +++ b/infer/src/backend/registerCheckers.ml @@ -175,7 +175,7 @@ let all_checkers = ; callbacks= [(Procedure Liveness.checker, Language.Clang)] } ; { name= "inefficient keyset iterator" ; active= Config.is_checker_enabled InefficientKeysetIterator - ; callbacks= [(Procedure InefficientKeysetIterator.checker, Language.Java)] } + ; callbacks= [(intraprocedural InefficientKeysetIterator.checker, Language.Java)] } ; { name= "immutable cast" ; active= Config.is_checker_enabled ImmutableCast ; callbacks= diff --git a/infer/src/checkers/inefficientKeysetIterator.ml b/infer/src/checkers/inefficientKeysetIterator.ml index 03d89ffa1..13071a8eb 100644 --- a/infer/src/checkers/inefficientKeysetIterator.ml +++ b/infer/src/checkers/inefficientKeysetIterator.ml @@ -52,7 +52,7 @@ let find_first_arg_pvar node ~fun_name ~class_name_f = else None -let report_matching_get tenv summary pvar loop_nodes : unit = +let report_matching_get attrs err_log tenv pvar loop_nodes : unit = LoopNodes.iter (fun node -> let instrs = Procdesc.Node.get_instrs node in @@ -75,7 +75,7 @@ let report_matching_get tenv summary pvar loop_nodes : unit = in let loc = Procdesc.Node.get_loc node in let ltr = [Errlog.make_trace_element 0 loc exp_desc []] in - SummaryReporting.log_error summary ~loc ~ltr + Reporting.log_error attrs err_log ~loc ~ltr IssueType.inefficient_keyset_iterator exp_desc ) ) ) loop_nodes @@ -102,12 +102,11 @@ let when_dominating_preds_satisfy idom my_node ~fun_name ~class_name_f ~f = aux my_node 4 -let checker Callbacks.{summary; exe_env} : Summary.t = - let proc_desc = Summary.get_proc_desc summary in - let tenv = Exe_env.get_tenv exe_env (Summary.get_proc_name summary) in +let checker {IntraproceduralAnalysis.proc_desc; tenv; err_log} = let cfg = CFG.from_pdesc proc_desc in let _, loop_head_to_loop_nodes = Loop_control.get_loop_control_maps cfg in let idom = Dominators.get_idoms proc_desc in + let attrs = Procdesc.get_attributes proc_desc in Procdesc.NodeMap.iter (fun loop_head loop_nodes -> if @@ -119,6 +118,5 @@ let checker Callbacks.{summary; exe_env} : Summary.t = ~class_name_f:(PatternMatch.implements_set tenv) ~f:(fun itr_node _ -> when_dominating_preds_satisfy idom itr_node ~fun_name:"keySet" ~class_name_f:(implements_map tenv) ~f:(fun _keySet_node get_pvar -> - report_matching_get tenv summary get_pvar loop_nodes ) ) ) - loop_head_to_loop_nodes ; - summary + report_matching_get attrs err_log tenv get_pvar loop_nodes ) ) ) + loop_head_to_loop_nodes diff --git a/infer/src/checkers/inefficientKeysetIterator.mli b/infer/src/checkers/inefficientKeysetIterator.mli new file mode 100644 index 000000000..623fe0d1c --- /dev/null +++ b/infer/src/checkers/inefficientKeysetIterator.mli @@ -0,0 +1,10 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open! IStd + +val checker : IntraproceduralAnalysis.t -> unit