Add --annotation-reachability-cxx-sources override option

Reviewed By: jeremydubreil

Differential Revision: D15063925

fbshipit-source-id: cbee2ef7d
master
David Lively 6 years ago committed by Facebook Github Bot
parent c85563d606
commit e0ce8c4392

@ -352,6 +352,10 @@ CLANG OPTIONS
go through a symbol starting with "Trusted::". go through a symbol starting with "Trusted::".
(default: []) (default: [])
--annotation-reachability-cxx-sources json
Override sources in all cxx annotation reachability specs with the
given sources spec (default: [])
--cxx-scope-guards json --cxx-scope-guards json
Specify scope guard classes that can be read only by destructors Specify scope guard classes that can be read only by destructors
without being reported as dead stores. (default: []) without being reported as dead stores. (default: [])

@ -96,6 +96,10 @@ OPTIONS
(default: []) (default: [])
See also infer-analyze(1). See also infer-analyze(1).
--annotation-reachability-cxx-sources json
Override sources in all cxx annotation reachability specs with the
given sources spec (default: []) See also infer-analyze(1).
--annotation-reachability-only --annotation-reachability-only
Activates: Enable --annotation-reachability and disable all other Activates: Enable --annotation-reachability and disable all other
checkers (Conversely: --no-annotation-reachability-only) checkers (Conversely: --no-annotation-reachability-only)

@ -96,6 +96,10 @@ OPTIONS
(default: []) (default: [])
See also infer-analyze(1). See also infer-analyze(1).
--annotation-reachability-cxx-sources json
Override sources in all cxx annotation reachability specs with the
given sources spec (default: []) See also infer-analyze(1).
--annotation-reachability-only --annotation-reachability-only
Activates: Enable --annotation-reachability and disable all other Activates: Enable --annotation-reachability and disable all other
checkers (Conversely: --no-annotation-reachability-only) checkers (Conversely: --no-annotation-reachability-only)

@ -769,6 +769,12 @@ This will cause us to create a new ISOLATED_REACHING_CONNECT issue for every fun
|} |}
and annotation_reachability_cxx_sources =
CLOpt.mk_json ~long:"annotation-reachability-cxx-sources"
~in_help:InferCommand.[(Analyze, manual_clang)]
{|Override sources in all cxx annotation reachability specs with the given sources spec|}
and annotation_reachability_custom_pairs = and annotation_reachability_custom_pairs =
CLOpt.mk_json ~long:"annotation-reachability-custom-pairs" CLOpt.mk_json ~long:"annotation-reachability-custom-pairs"
~in_help:InferCommand.[(Analyze, manual_java)] ~in_help:InferCommand.[(Analyze, manual_java)]
@ -2552,6 +2558,8 @@ and annotation_reachability = !annotation_reachability
and annotation_reachability_cxx = !annotation_reachability_cxx and annotation_reachability_cxx = !annotation_reachability_cxx
and annotation_reachability_cxx_sources = !annotation_reachability_cxx_sources
and annotation_reachability_custom_pairs = !annotation_reachability_custom_pairs and annotation_reachability_custom_pairs = !annotation_reachability_custom_pairs
and append_buck_flavors = !append_buck_flavors and append_buck_flavors = !append_buck_flavors

@ -227,6 +227,8 @@ val annotation_reachability : bool
val annotation_reachability_cxx : Yojson.Basic.json val annotation_reachability_cxx : Yojson.Basic.json
val annotation_reachability_cxx_sources : Yojson.Basic.json
val annotation_reachability_custom_pairs : Yojson.Basic.json val annotation_reachability_custom_pairs : Yojson.Basic.json
val anon_args : string list val anon_args : string list

@ -287,6 +287,8 @@ module CxxAnnotationSpecs = struct
let option_name = "--annotation-reachability-cxx" let option_name = "--annotation-reachability-cxx"
let src_option_name = "--annotation-reachability-cxx-sources"
let cxx_string_of_pname pname = let cxx_string_of_pname pname =
let chop_prefix s = let chop_prefix s =
String.chop_prefix s ~prefix:Config.clang_inner_destructor_prefix |> Option.value ~default:s String.chop_prefix s ~prefix:Config.clang_inner_destructor_prefix |> Option.value ~default:s
@ -299,7 +301,7 @@ module CxxAnnotationSpecs = struct
^ "()" ^ "()"
let spec_from_config spec_name spec_cfg = let spec_from_config spec_name spec_cfg source_overrides =
let src = option_name ^ " -> " ^ spec_name in let src = option_name ^ " -> " ^ spec_name in
let make_pname_pred entry ~src : Typ.Procname.t -> bool = let make_pname_pred entry ~src : Typ.Procname.t -> bool =
let symbols = U.yojson_lookup entry "symbols" ~src ~f:U.string_list_of_yojson ~default:[] in let symbols = U.yojson_lookup entry "symbols" ~src ~f:U.string_list_of_yojson ~default:[] in
@ -316,8 +318,12 @@ module CxxAnnotationSpecs = struct
| _, _ -> | _, _ ->
fun pname -> sym_pred pname || path_pred pname fun pname -> sym_pred pname || path_pred pname
in in
let sources = U.yojson_lookup spec_cfg "sources" ~src ~f:U.assoc_of_yojson ~default:[] in let sources, sources_src =
let sources_src = src ^ " -> sources" in if List.length source_overrides > 0 then (source_overrides, src_option_name)
else
( U.yojson_lookup spec_cfg "sources" ~src ~f:U.assoc_of_yojson ~default:[]
, src ^ " -> sources" )
in
let src_name = spec_name ^ "-source" in let src_name = spec_name ^ "-source" in
let src_desc = let src_desc =
U.yojson_lookup sources "desc" ~src:sources_src ~f:U.string_of_yojson ~default:src_name U.yojson_lookup sources "desc" ~src:sources_src ~f:U.string_of_yojson ~default:src_name
@ -392,11 +398,16 @@ module CxxAnnotationSpecs = struct
U.assoc_of_yojson Config.annotation_reachability_cxx ~src:option_name U.assoc_of_yojson Config.annotation_reachability_cxx ~src:option_name
let annotation_reachability_cxx_sources =
U.assoc_of_yojson Config.annotation_reachability_cxx_sources ~src:src_option_name
let from_config () : 'AnnotationSpec list = let from_config () : 'AnnotationSpec list =
List.map List.map
~f:(fun (spec_name, spec_cfg) -> ~f:(fun (spec_name, spec_cfg) ->
let src = option_name ^ " -> " ^ spec_name in let src = option_name ^ " -> " ^ spec_name in
spec_from_config spec_name (U.assoc_of_yojson spec_cfg ~src) ) spec_from_config spec_name (U.assoc_of_yojson spec_cfg ~src)
annotation_reachability_cxx_sources )
annotation_reachability_cxx annotation_reachability_cxx
end end

@ -0,0 +1,18 @@
# Copyright (c) 2019-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
TESTS_DIR = ../../../..
# see explanations in cpp/errors/Makefile for the custom isystem
CLANG_OPTIONS = -x c++ -std=c++11 -nostdinc++ -isystem$(ROOT_DIR) -isystem$(CLANG_INCLUDES)/c++/v1/ -c
INFER_OPTIONS = --annotation-reachability-only --debug-exceptions --project-root $(TESTS_DIR) --annotation-reachability-cxx '{ "TEST_ANNOT_REACH": { "sources": { "symbols": [ "CheckFrom::" ] }, "sinks": { "overrides": { "symbols": [ "Good::"], "paths": [ "codetoanalyze/cpp/annotation-reachability/reachability-approved.cpp" ] },"symbols": [ "Danger::", "death" ] } } }' --annotation-reachability-cxx-sources '{ "symbols": [ "CheckFrom::danger_via", "CheckFrom::death_via" ] }'
INFERPRINT_OPTIONS = --issues-tests
SOURCES = $(wildcard ../*.cpp)
include $(TESTS_DIR)/clang.make
infer-out/report.json: $(MAKEFILE_LIST)

@ -0,0 +1,2 @@
codetoanalyze/cpp/annotation-reachability/reachability.cpp, CheckFrom::danger_via, 2, TEST_ANNOT_REACH, no_bucket, ERROR, []
codetoanalyze/cpp/annotation-reachability/reachability.cpp, CheckFrom::death_via, 0, TEST_ANNOT_REACH, no_bucket, ERROR, []
Loading…
Cancel
Save