Allow Cxx annotation-reachability src/sink/override w/paths AND symbols

Reviewed By: jvillard

Differential Revision: D14841296

fbshipit-source-id: dfbd1b3ab
master
David Lively 6 years ago committed by Facebook Github Bot
parent 74b7345fd2
commit 996f7c4f02

@ -304,13 +304,17 @@ module CxxAnnotationSpecs = struct
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 paths = U.yojson_lookup entry "paths" ~src ~f:U.string_list_of_yojson ~default:[] in
if not (List.is_empty symbols) then (
if not (List.is_empty paths) then
Logging.(die UserError) "Cannot specify both `paths` and `symbols` in %s" src ;
fun pname -> List.exists ~f:(symbol_match (Typ.Procname.to_string pname)) symbols )
else if not (List.is_empty paths) then fun pname ->
List.exists ~f:(path_match (src_path_of pname)) paths
else Logging.(die UserError) "Must specify either `paths` or `symbols` in %s" src
let sym_pred pname = List.exists ~f:(symbol_match (Typ.Procname.to_string pname)) symbols in
let path_pred pname = List.exists ~f:(path_match (src_path_of pname)) paths in
match (symbols, paths) with
| [], [] ->
Logging.(die UserError) "Must specify either `paths` or `symbols` in %s" src
| _, [] ->
sym_pred
| [], _ ->
path_pred
| _, _ ->
fun pname -> sym_pred pname || path_pred pname
in
let sources = U.yojson_lookup spec_cfg "sources" ~src ~f:U.assoc_of_yojson ~default:[] in
let sources_src = src ^ " -> sources" in

@ -7,7 +7,7 @@ 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": [ "Approved::"] },"symbols": [ "Danger::", "death" ] } } }'
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" ] } } }'
INFERPRINT_OPTIONS = --issues-tests

@ -0,0 +1,16 @@
/*
* 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.
*/
#include <stdlib.h>
void death() { exit(-1); }
void good() {}
namespace Approved {
void baz() { death(); }
} // namespace Approved

@ -0,0 +1,15 @@
/*
* 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.
*/
#pragma once
void death();
namespace Approved {
void baz();
}
void good();

@ -4,25 +4,18 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "reachability-approved.h"
namespace Danger {
void foo();
void bar();
} // namespace Danger
void death();
void good();
namespace Ok {
void foo();
void bar();
} // namespace Ok
namespace Approved {
void baz() { death(); }
} // namespace Approved
namespace CheckFrom {
void death_via() { death(); }

Loading…
Cancel
Save