Skip to content

Commit

Permalink
[report] Adding a flag to specify false positives to skip
Browse files Browse the repository at this point in the history
Summary:
Sometimes users know that Infer found a false positive and would like to suppress it. Now we have a way. We can't use line to specify the issue because that changes too quickly, we we specify bug_type, file, class and method.

We could also add some relevant variable names or such in the future.

Reviewed By: jvillard

Differential Revision: D57112894

fbshipit-source-id: ab69a5d121e70acc56f0982485bb3956bd4b7eec
  • Loading branch information
dulmarod authored and facebook-github-bot committed May 10, 2024
1 parent bcb4b88 commit 504b807
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 4 deletions.
16 changes: 15 additions & 1 deletion .inferconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,19 @@
{
"source_contains": "_SHOULD_BE_SKIPPED_"
}
],
"report-block-list-spec": [
{
"bug_type" : "RETAIN_CYCLE",
"file" : "pulse/retain_cycles/RetainCycleBlocks.m",
"procedure_name" : "retain_a_in_block_cycle_bad",
"comment": "This is not really a FP, just testing."
},
{
"bug_type" : "RETAIN_CYCLE",
"file" : "pulse/retain_cycles/RetainCycleBlocks.m",
"class_name" : "RCBlock",
"procedure_name" : "retain_self_in_block_retain_cycle_bad"
}
]
}
}
18 changes: 18 additions & 0 deletions infer/man/man1/infer-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,24 @@ OPTIONS
by --report-allow-list-path-regex
See also infer-report(1) and infer-run(1).

--report-block-list-spec json
Do not report the issues in this list.
Example format:
"report-block-list-spec": [
{ "bug_type": "CXX_REF_CAPTURED_IN_BLOCK",
"procedure_name": "foo",
"file": "path/to/File.m"
"comment": "This is a fp because..."
},
{ "bug_type": "RETAIN_CYCLE",
"class_name": "MyClass",
"procedure_name": "my_method"
"file": "path/to/File.m"
}
]

See also infer-report(1) and infer-run(1).

--report-console-limit int
Maximum number of issues to display on standard output. Unset with
--report-console-limit-reset to show all.
Expand Down
17 changes: 17 additions & 0 deletions infer/man/man1/infer-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,23 @@ OPTIONS
specified OCaml regex, even if they match the allow list specified
by --report-allow-list-path-regex

--report-block-list-spec json
Do not report the issues in this list.
Example format:
"report-block-list-spec": [
{ "bug_type": "CXX_REF_CAPTURED_IN_BLOCK",
"procedure_name": "foo",
"file": "path/to/File.m"
"comment": "This is a fp because..."
},
{ "bug_type": "RETAIN_CYCLE",
"class_name": "MyClass",
"procedure_name": "my_method"
"file": "path/to/File.m"
}
]


--report-console-limit int
Maximum number of issues to display on standard output. Unset with
--report-console-limit-reset to show all.
Expand Down
17 changes: 17 additions & 0 deletions infer/man/man1/infer-run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ OPTIONS
specified OCaml regex, even if they match the allow list specified
by --report-allow-list-path-regex

--report-block-list-spec json
Do not report the issues in this list.
Example format:
"report-block-list-spec": [
{ "bug_type": "CXX_REF_CAPTURED_IN_BLOCK",
"procedure_name": "foo",
"file": "path/to/File.m"
"comment": "This is a fp because..."
},
{ "bug_type": "RETAIN_CYCLE",
"class_name": "MyClass",
"procedure_name": "my_method"
"file": "path/to/File.m"
}
]


--report-force-relative-path
Activates: Force converting an absolute path to a relative path to
the root directory (Conversely: --no-report-force-relative-path)
Expand Down
18 changes: 18 additions & 0 deletions infer/man/man1/infer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,24 @@ OPTIONS
by --report-allow-list-path-regex
See also infer-report(1) and infer-run(1).

--report-block-list-spec json
Do not report the issues in this list.
Example format:
"report-block-list-spec": [
{ "bug_type": "CXX_REF_CAPTURED_IN_BLOCK",
"procedure_name": "foo",
"file": "path/to/File.m"
"comment": "This is a fp because..."
},
{ "bug_type": "RETAIN_CYCLE",
"class_name": "MyClass",
"procedure_name": "my_method"
"file": "path/to/File.m"
}
]

See also infer-report(1) and infer-run(1).

--report-console-limit int
Maximum number of issues to display on standard output. Unset with
--report-console-limit-reset to show all.
Expand Down
14 changes: 14 additions & 0 deletions infer/src/atd/dune
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,17 @@
(deps pulse_config.atd)
(action
(run atdgen -t %{deps})))

; ATD for report_block_list_spec

(rule
(targets report_block_list_spec_j.ml report_block_list_spec_j.mli)
(deps report_block_list_spec.atd)
(action
(run atdgen -j -j-std %{deps})))

(rule
(targets report_block_list_spec_t.ml report_block_list_spec_t.mli)
(deps report_block_list_spec.atd)
(action
(run atdgen -t %{deps})))
16 changes: 16 additions & 0 deletions infer/src/atd/report_block_list_spec.atd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(*
* 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 report_block_list_spec = {
bug_type : string;
?class_name: string option;
procedure_name: string;
file : string;
?comment: string option
}

type report_block_list_specs = report_block_list_spec list
25 changes: 25 additions & 0 deletions infer/src/base/Config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3118,6 +3118,26 @@ and ( report_block_list_files_containing
~meta:"error_name" () )


and report_block_list_spec =
CLOpt.mk_json ~long:"report-block-list-spec"
~in_help:InferCommand.[(Report, manual_generic); (Run, manual_generic)]
{|Do not report the issues in this list.
Example format:
"report-block-list-spec": [
{ "bug_type": "CXX_REF_CAPTURED_IN_BLOCK",
"procedure_name": "foo",
"file": "path/to/File.m"
"comment": "This is a fp because..."
},
{ "bug_type": "RETAIN_CYCLE",
"class_name": "MyClass",
"procedure_name": "my_method"
"file": "path/to/File.m"
}
]
|}


and report_console_limit =
CLOpt.mk_int_opt ~long:"report-console-limit" ~default:5
~in_help:InferCommand.[(Report, manual_generic)]
Expand Down Expand Up @@ -4645,6 +4665,11 @@ and replay_ondemand_should_error = !replay_ondemand_should_error

and report = !report

and report_block_list_spec =
Report_block_list_spec_j.report_block_list_specs_of_string
(Yojson.Safe.to_string !report_block_list_spec)


and report_block_list_files_containing = RevList.to_list !report_block_list_files_containing

and report_console_limit = !report_console_limit
Expand Down
2 changes: 2 additions & 0 deletions infer/src/base/Config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ val replay_ondemand_should_error : bool

val report : bool

val report_block_list_spec : Report_block_list_spec_t.report_block_list_specs

val report_block_list_files_containing : string list

val report_console_limit : int option
Expand Down
35 changes: 34 additions & 1 deletion infer/src/integration/JsonReports.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,35 @@ let is_in_clang_header source_file =
~substring:"/facebook-clang-plugins/clang/install/include/"


let issue_in_report_block_list_specs ~file ~issue ~proc =
let is_in_report_block_list_spec ~file ~issue ~proc report_block_list_spec =
let filter_class =
match
(Procname.get_class_name proc, report_block_list_spec.Report_block_list_spec_t.class_name)
with
| Some class_name, Some fp_class_name ->
String.is_substring ~substring:fp_class_name class_name
| _ ->
true
in
let filter_proc =
let proc_name = Procname.get_method proc in
String.is_substring ~substring:report_block_list_spec.Report_block_list_spec_t.procedure_name
proc_name
in
let filter_file =
String.is_substring ~substring:report_block_list_spec.Report_block_list_spec_t.file
(SourceFile.to_rel_path file)
in
let filter_error =
String.equal issue.IssueType.unique_id
report_block_list_spec.Report_block_list_spec_t.bug_type
in
filter_class && filter_proc && filter_file && filter_error
in
List.exists ~f:(is_in_report_block_list_spec ~file ~issue ~proc) Config.report_block_list_spec


module JsonIssuePrinter = MakeJsonListPrinter (struct
type elt = json_issue_printer_typ

Expand All @@ -215,7 +244,11 @@ module JsonIssuePrinter = MakeJsonListPrinter (struct
error_filter source_file err_key.issue_type
&& should_report_proc_name
&& should_report proc_name err_key.issue_type err_key.err_desc
&& not (is_in_clang_header source_file)
&& (not (is_in_clang_header source_file))
&& should_report proc_name err_key.issue_type err_key.err_desc
&& not
(issue_in_report_block_list_specs ~file:source_file ~issue:err_key.issue_type
~proc:proc_name )
then
let severity = IssueType.string_of_severity err_key.severity in
let category = IssueType.string_of_category err_key.issue_type.category in
Expand Down
2 changes: 0 additions & 2 deletions infer/tests/codetoanalyze/objc/pulse/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ codetoanalyze/objc/pulse/retain_cycles/BrokenCycles.m, broken_self_strong_cycle_
codetoanalyze/objc/pulse/retain_cycles/IvarInheritanceRetainCycle.m, field_superclass_main, 3, RETAIN_CYCLE, no_bucket, ERROR, [assignment of b->a part of the trace starts here,allocated by call to `alloc` (modelled),in call to `NSObject.init` (modelled),assigned,assigned,retain cycle here]
codetoanalyze/objc/pulse/retain_cycles/RetainCycleBlockAsParameter.m, FBSomeDataManager.fetchNewData_bad, 2, RETAIN_CYCLE, no_bucket, ERROR, [assignment of self->_fetcher part of the trace starts here,parameter `self` of FBSomeDataManager.fetchNewData_bad,assigned,assignment of &block defined in RetainCycleBlockAsParameter.m:46 part of the trace starts here,allocated by call to `alloc` (modelled),when calling `Fetcher.initWithCompletionBlock:` here,parameter `self` of Fetcher.initWithCompletionBlock:,assigned,self captured by block defined in RetainCycleBlockAsParameter.m:46 here,retain cycle here]
codetoanalyze/objc/pulse/retain_cycles/RetainCycleBlockCapturedVar.m, LinkResolver.test, 3, RETAIN_CYCLE, no_bucket, ERROR, [retainedListener captured by block defined in RetainCycleBlockCapturedVar.m:32 here,assignment of listener->_didFinishLoad part of the trace starts here,allocated by call to `alloc` (modelled),in call to `NSObject.init` (modelled),assigned,when calling `Listener.setDidFinishLoad:` here,parameter `self` of Listener.setDidFinishLoad:,assigned,retainedListener captured by block defined in RetainCycleBlockCapturedVar.m:32 here,retain cycle here]
codetoanalyze/objc/pulse/retain_cycles/RetainCycleBlocks.m, RCBlock.retain_self_in_block_retain_cycle_bad, 1, RETAIN_CYCLE, no_bucket, ERROR, [assignment of self->_handler part of the trace starts here,parameter `self` of RCBlock.retain_self_in_block_retain_cycle_bad,when calling `RCBlock.setHandler:` here,parameter `self` of RCBlock.setHandler:,assigned,self captured by block defined in RetainCycleBlocks.m:49 here,retain cycle here]
codetoanalyze/objc/pulse/retain_cycles/RetainCycleBlocks.m, retain_a_in_block_cycle_bad, 4, RETAIN_CYCLE, no_bucket, ERROR, [assignment of a->_b part of the trace starts here,allocated by call to `alloc` (modelled),in call to `NSObject.init` (modelled),assigned,when calling `RCBlockAA.setB:` here,parameter `self` of RCBlockAA.setB:,assigned,assignment of b->_a_handler part of the trace starts here,allocated by call to `alloc` (modelled),in call to `NSObject.init` (modelled),assigned,when calling `RCBlock.setA_handler:` here,parameter `self` of RCBlock.setA_handler:,assigned,a captured by block defined in RetainCycleBlocks.m:81 here,retain cycle here]
codetoanalyze/objc/pulse/retain_cycles/RetainCycleBlocksCopy.m, Process.retain_self_in_block_bad, 1, RETAIN_CYCLE, no_bucket, ERROR, [assignment of self->_handler part of the trace starts here,parameter `self` of Process.retain_self_in_block_bad,when calling `Process.setHandler:` here,parameter `self` of Process.setHandler:,assigned,self captured by block defined in RetainCycleBlocksCopy.m:24 here,retain cycle here]
codetoanalyze/objc/pulse/retain_cycles/RetainCycleDeduplication.m, CViewController.setCaptureInteractionController_bad:, 5, RETAIN_CYCLE, no_bucket, ERROR, [assignment of self->_captureController part of the trace starts here,parameter `self` of CViewController.setCaptureInteractionController_bad:,assigned,assignment of self->_captureController->_delegate part of the trace starts here,parameter `self` of CViewController.setCaptureInteractionController_bad:,parameter `captureController` of CViewController.setCaptureInteractionController_bad:,taking "then" branch,assigned,when calling `CaptureController.setDelegate:` here,parameter `self` of CaptureController.setDelegate:,assigned,retain cycle here]
codetoanalyze/objc/pulse/retain_cycles/RetainCycleExampleWeak.m, RetainCycleExampleWeak.test_strong_adapter_cycle_bad, 1, RETAIN_CYCLE, no_bucket, ERROR, [assignment of self->_feed.strong_adapter._feed part of the trace starts here,parameter `self` of RetainCycleExampleWeak.test_strong_adapter_cycle_bad,in call to `AFeed.strong_adapter`,parameter `self` of AFeed.strong_adapter,returned,return from call to `AFeed.strong_adapter`,when calling `Adapter.setFeed:` here,parameter `self` of Adapter.setFeed:,assigned,retain cycle here]
Expand Down

0 comments on commit 504b807

Please sign in to comment.