[ConfigImpact] Only report on functions that occur on a given json config data

Summary:
Currently, we report on all functions that are not config checked. However, the aim of the analysis is to only report on these for specific functions. Moreover, this has performance implications in practice.

This diff instead reports on functions that occur on a json file that is passed by the command line option `config-data-file`.

Reviewed By: skcho

Differential Revision: D26666336

fbshipit-source-id: 290cd3ada
master
Ezgi Çiçek 4 years ago committed by Facebook GitHub Bot
parent 92ad9f1ed9
commit 7f9d56b1b5

@ -268,6 +268,10 @@ OPTIONS
checkers (Conversely: --no-config-impact-analysis-only)
See also infer-analyze(1).
--config-impact-data-file file
[ConfigImpact] Specify the file containing the config data
See also infer-report(1).
--continue
Activates: Continue the capture for the reactive analysis,
increasing the changed files/procedures. (If a procedure was
@ -1451,6 +1455,9 @@ INTERNAL OPTIONS
--compilation-database-reset
Set --compilation-database to the empty list.
--config-impact-data-file-reset
Cancel the effect of --config-impact-data-file.
--cost-issues-tests-reset
Cancel the effect of --cost-issues-tests.

@ -35,6 +35,9 @@ OPTIONS
`<reason_string>` is a non-empty string used to explain why the
issue was filtered.
--config-impact-data-file file
[ConfigImpact] Specify the file containing the config data
--cost-issues-tests file
Write a list of cost issues in a format suitable for cost tests to
file

@ -268,6 +268,10 @@ OPTIONS
checkers (Conversely: --no-config-impact-analysis-only)
See also infer-analyze(1).
--config-impact-data-file file
[ConfigImpact] Specify the file containing the config data
See also infer-report(1).
--continue
Activates: Continue the capture for the reactive analysis,
increasing the changed files/procedures. (If a procedure was

@ -0,0 +1,12 @@
(*
* 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.
*)
type config_item = {
method_name: string;
class_name: string
}
type config_data = config_item list

@ -61,6 +61,20 @@
(action
(run atdgen -t %{deps})))
; ATD for config_impact_data
(rule
(targets config_impact_data_j.ml config_impact_data_j.mli)
(deps config_impact_data.atd)
(action
(run atdgen -j -j-std %{deps})))
(rule
(targets config_impact_data_t.ml config_impact_data_t.mli)
(deps config_impact_data.atd)
(action
(run atdgen -t %{deps})))
; ATD for java_profiler_samples
(rule

@ -913,6 +913,12 @@ and compilation_database_escaped =
from Xcode (can be specified multiple times)"
and config_impact_data_file =
CLOpt.mk_path_opt ~long:"config-impact-data-file"
~in_help:InferCommand.[(Report, manual_generic)]
~meta:"file" "[ConfigImpact] Specify the file containing the config data"
(** Continue the capture for reactive mode: If a procedure was changed beforehand, keep the changed
marking. *)
and continue =
@ -2848,6 +2854,8 @@ and clang_libcxx_include_to_override_regex = !clang_libcxx_include_to_override_r
and classpath = !classpath
and config_impact_data_file = !config_impact_data_file
and continue_analysis = !continue_analysis
and continue_capture = !continue

@ -226,6 +226,8 @@ val clang_libcxx_include_to_override_regex : string option
val command : InferCommand.t
val config_impact_data_file : string option
val continue_analysis : bool
val continue_capture : bool

@ -70,9 +70,11 @@ module UncheckedCallee = struct
let report {InterproceduralAnalysis.proc_desc; err_log} x =
let desc = F.asprintf "%a without config check" pp x in
Reporting.log_issue proc_desc err_log ~loc:(get_location x) ~ltr:(make_err_trace x)
ConfigImpactAnalysis IssueType.config_impact_analysis desc
let pname = Procdesc.get_proc_name proc_desc in
if ExternalConfigImpactData.is_in_config_data_file pname then
let desc = F.asprintf "%a without config check" pp x in
Reporting.log_issue proc_desc err_log ~loc:(get_location x) ~ltr:(make_err_trace x)
ConfigImpactAnalysis IssueType.config_impact_analysis desc
end
module UncheckedCallees = struct

@ -0,0 +1,40 @@
(*
* 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
module L = Logging
module ConfigProcnameSet = Caml.Set.Make (struct
(* workaround: since there is no way to have @@deriving directive
in atd declaration, we redefine the type *)
type t = Config_impact_data_t.config_item = {method_name: string; class_name: string}
[@@deriving compare]
end)
let read_file_config_data fname =
let config_list =
try Atdgen_runtime.Util.Json.from_file Config_impact_data_j.read_config_data fname
with e ->
L.user_warning "Failed to read file '%s': %s@." fname (Exn.to_string e) ;
[]
in
List.fold config_list ~init:ConfigProcnameSet.empty ~f:(fun acc itm ->
ConfigProcnameSet.add itm acc )
let is_in_config_data_file =
let config_data =
Option.value_map Config.config_impact_data_file ~default:ConfigProcnameSet.empty
~f:read_file_config_data
in
fun proc_name ->
ConfigProcnameSet.exists
(fun {method_name; class_name} ->
String.equal method_name (Procname.get_method proc_name)
&& String.equal class_name (Procname.get_class_name proc_name |> Option.value ~default:"")
)
config_data

@ -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 is_in_config_data_file : Procname.t -> bool

@ -5,7 +5,7 @@
TESTS_DIR = ../../..
INFER_OPTIONS = --config-impact-analysis-only --debug-exceptions \
INFER_OPTIONS = --config-impact-analysis-only --config-impact-data-file config_data.json --debug-exceptions \
--report-force-relative-path
INFERPRINT_OPTIONS = --issues-tests
SOURCES = $(wildcard *.java)

@ -6,7 +6,7 @@
TESTS_DIR = ../../..
CLANG_OPTIONS = -c $(OBJC_CLANG_OPTIONS)
INFER_OPTIONS = --config-impact-analysis-only -g --debug-exceptions \
INFER_OPTIONS = --config-impact-analysis-only --config-impact-data-file config_data.json --debug-exceptions \
--report-force-relative-path --project-root $(TESTS_DIR)
INFERPRINT_OPTIONS = --issues-tests

@ -1 +1,3 @@
../../facebook/skel/infer/tests/codetoanalyze/objc/fb-config-impact/Basic.m, qe_unchecked_bad, 4, CONFIG_IMPACT, no_bucket, ADVICE, [callee2 is called]
../../facebook/skel/infer/tests/codetoanalyze/objc/fb-config-impact/ClassTest.m, MyClass.call_log_bad:data:, 4, CONFIG_IMPACT, no_bucket, ADVICE, [__objc_alloc_no_fail is called]
../../facebook/skel/infer/tests/codetoanalyze/objc/fb-config-impact/ClassTest.m, MyClass.call_log_bad:data:, 4, CONFIG_IMPACT, no_bucket, ADVICE, [NSKeyedUnarchiver.initForReadingFromData:error: is called]

Loading…
Cancel
Save