Add a config option to whitelist common initializer values for liveness analysis (#1340)

Summary:
Implements https://github.com/facebook/infer/issues/1083

Pull Request resolved: https://github.com/facebook/infer/pull/1340

Reviewed By: mityal

Differential Revision: D24956747

Pulled By: jvillard

fbshipit-source-id: 820eb538a
master
Joscha Benz 4 years ago committed by Facebook GitHub Bot
parent bab5aa4b08
commit 606a3c95d9

@ -200,6 +200,9 @@ OPTIONS
Deactivates: checker liveness: Detection of dead stores and unused
variables. (Conversely: --liveness)
--liveness-ignored-constant +string
List of integer constants to be ignored by liveness analysis
--liveness-only
Activates: Enable liveness and disable all other checkers
(Conversely: --no-liveness-only)

@ -790,6 +790,10 @@ OPTIONS
unique_ptr<type>) will count as dead stores when the variables are
not read explicitly by the program. See also infer-analyze(1).
--liveness-ignored-constant +string
List of integer constants to be ignored by liveness analysis
See also infer-analyze(1).
--liveness-only
Activates: Enable liveness and disable all other checkers
(Conversely: --no-liveness-only) See also infer-analyze(1).
@ -1597,6 +1601,9 @@ INTERNAL OPTIONS
--linters-doc-url-reset
Set --linters-doc-url to the empty list.
--liveness-ignored-constant-reset
Set --liveness-ignored-constant to the empty list.
--load-average-reset
Cancel the effect of --load-average.

@ -790,6 +790,10 @@ OPTIONS
unique_ptr<type>) will count as dead stores when the variables are
not read explicitly by the program. See also infer-analyze(1).
--liveness-ignored-constant +string
List of integer constants to be ignored by liveness analysis
See also infer-analyze(1).
--liveness-only
Activates: Enable liveness and disable all other checkers
(Conversely: --no-liveness-only) See also infer-analyze(1).

@ -1497,6 +1497,12 @@ and liveness_dangerous_classes =
by the program."
and liveness_ignored_constant =
CLOpt.mk_string_list ~default:["0"] ~long:"liveness-ignored-constant"
~in_help:InferCommand.[(Analyze, manual_generic)]
"List of integer constants to be ignored by liveness analysis"
and _log_events =
CLOpt.mk_bool ~long:"" ~deprecated:["-log-events"] ~deprecated_no:["-no-log-events"]
"[DOES NOTHING] Turn on the feature that logs events in a machine-readable format"
@ -2962,6 +2968,8 @@ and list_issue_types = !list_issue_types
and liveness_dangerous_classes = !liveness_dangerous_classes
and liveness_ignored_constant = !liveness_ignored_constant
and load_average =
match !load_average with None when !buck -> Some (float_of_int ncpu) | _ -> !load_average

@ -376,6 +376,8 @@ val list_issue_types : bool
val liveness_dangerous_classes : Yojson.Basic.t
val liveness_ignored_constant : string list
val max_nesting : int option
val merge : bool

@ -212,6 +212,21 @@ let get_captured_by_ref_invariant_map proc_desc =
CapturedByRefAnalyzer.exec_cfg cfg () ~initial:VarSet.empty
module IntLitSet = Caml.Set.Make (IntLit)
let ignored_constants =
let int_lit_constants =
List.map
~f:(fun el ->
try IntLit.of_string el
with Invalid_argument _ ->
L.die UserError
"Ill-formed option '%s' for --liveness-ignored-constant: an integer was expected" el )
Config.liveness_ignored_constant
in
IntLitSet.of_list int_lit_constants
let checker {IntraproceduralAnalysis.proc_desc; err_log} =
let captured_by_ref_invariant_map = get_captured_by_ref_invariant_map proc_desc in
let cfg = CFG.from_pdesc proc_desc in
@ -223,9 +238,13 @@ let checker {IntraproceduralAnalysis.proc_desc; err_log} =
| Exp.Cast (_, e) ->
is_sentinel_exp e
| Exp.Const (Cint i) ->
IntLit.iszero i || IntLit.isnull i
| Exp.Const (Cfloat 0.0) ->
true
IntLitSet.mem i ignored_constants
| Exp.Const (Cfloat f) -> (
match Z.of_float f with
| z ->
IntLitSet.mem (IntLit.of_big_int z) ignored_constants
| exception Z.Overflow ->
false )
| _ ->
false
in

@ -1,4 +1,5 @@
{
"liveness-ignored-constant" : ["44"],
"liveness-dangerous-classes": [
"dead_stores::BlacklistedStruct"
],

@ -609,4 +609,10 @@ void switch_with_temporary_ok() {
};
}
void ignored_constants_ok() {
int x = 0;
float f = 0.0;
int z = 44;
}
} // namespace dead_stores

Loading…
Cancel
Save