Add initial version (k=1, undirected) of the bounder calltree analysis checker for the Semantic Blame project
Reviewed By: sblackshear Differential Revision: D3568420 fbshipit-source-id: cc58a93master
parent
e94fc21410
commit
b9a5a3b5ad
@ -0,0 +1,50 @@
|
||||
(*
|
||||
* Copyright (c) 2016 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
open! Utils
|
||||
|
||||
module F = Format
|
||||
module L = Logging
|
||||
|
||||
(** find transitive procedure calls for each procedure *)
|
||||
|
||||
module ProcnameSet = PrettyPrintable.MakePPSet(struct
|
||||
type t = Procname.t
|
||||
let compare = Procname.compare
|
||||
let pp_element = Procname.pp
|
||||
end)
|
||||
|
||||
module Domain = AbstractDomain.FiniteSet(ProcnameSet)
|
||||
|
||||
module TransferFunctions (CFG : ProcCfg.S) = struct
|
||||
module CFG = CFG
|
||||
module Domain = Domain
|
||||
type extras = ProcData.no_extras
|
||||
|
||||
let exec_instr astate _ _ = function
|
||||
| Sil.Call (_, Const (Const.Cfun pn), _, _, _) ->
|
||||
Domain.add pn astate
|
||||
| Sil.Call _ ->
|
||||
(** We currently ignore calls through function pointers in C and
|
||||
* other potential special kinds of procedure calls to be added later,
|
||||
* e.g. Java reflection. *)
|
||||
astate
|
||||
| Sil.Letderef _ | Set _ | Prune _ | Declare_locals _
|
||||
| Stackop _ | Remove_temps _ | Abstract _ | Nullify _ ->
|
||||
astate
|
||||
end
|
||||
|
||||
module Analyzer =
|
||||
AbstractInterpreter.Make
|
||||
(ProcCfg.Exceptional)
|
||||
(Scheduler.ReversePostorder)
|
||||
(TransferFunctions)
|
||||
|
||||
let checker { Callbacks.proc_desc; tenv; } =
|
||||
ignore(Analyzer.exec_pdesc (ProcData.make_default proc_desc tenv))
|
@ -0,0 +1,52 @@
|
||||
(*
|
||||
* Copyright (c) 2016 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
open! Utils
|
||||
|
||||
module F = Format
|
||||
|
||||
module TestInterpreter = AnalyzerTester.Make
|
||||
(ProcCfg.Exceptional)
|
||||
(Scheduler.ReversePostorder)
|
||||
(BoundedCallTree.TransferFunctions)
|
||||
|
||||
let tests =
|
||||
let open OUnit2 in
|
||||
let open AnalyzerTester.StructuredSil in
|
||||
let f_proc_name = Procname.from_string_c_fun "f" in
|
||||
let g_proc_name = Procname.from_string_c_fun "g" in
|
||||
let g_args = [((Sil.Const (Const.Cint (IntLit.one))), (Typ.Tint IInt))] in
|
||||
let g_ret_ids = [(ident_of_str "r")] in
|
||||
let test_list = [
|
||||
"on_call_add_proc_name",
|
||||
[
|
||||
make_call ~procname:f_proc_name [] []; (* means f() *)
|
||||
invariant "{ f }"
|
||||
];
|
||||
"on_call_add_proc_name_w_args",
|
||||
[
|
||||
make_call ~procname:g_proc_name g_ret_ids g_args; (* means r = a.g(1) *)
|
||||
invariant "{ g }"
|
||||
];
|
||||
"handle_two_proc_calls",
|
||||
[
|
||||
make_call ~procname:f_proc_name [] [];
|
||||
invariant "{ f }";
|
||||
make_call ~procname:g_proc_name g_ret_ids g_args;
|
||||
invariant "{ f, g }"
|
||||
];
|
||||
"dont_record_procs_twice",
|
||||
[
|
||||
make_call ~procname:f_proc_name [] [];
|
||||
invariant "{ f }";
|
||||
make_call ~procname:f_proc_name [] [];
|
||||
invariant "{ f }"
|
||||
];
|
||||
] |> TestInterpreter.create_tests ProcData.empty_extras in
|
||||
"bounded_calltree_test_suite">:::test_list
|
Loading…
Reference in new issue