From d082f364488863169986b2b868915b86978b9460 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Wed, 8 May 2019 06:21:40 -0700 Subject: [PATCH] [sqlite] calls in the db Reviewed By: mbouaziz, martintrojer Differential Revision: D15199334 fbshipit-source-id: 7938a2024 --- infer/src/IR/Attributes.ml | 7 +++++-- infer/src/IR/Procdesc.ml | 12 ++++++++++++ infer/src/IR/Procdesc.mli | 3 +++ infer/src/base/MergeResults.ml | 2 +- infer/src/base/ResultsDatabase.ml | 1 + 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/infer/src/IR/Attributes.ml b/infer/src/IR/Attributes.ml index 14a6a9eef..61f98097a 100644 --- a/infer/src/IR/Attributes.ml +++ b/infer/src/IR/Attributes.ml @@ -52,7 +52,7 @@ let replace_statement = ResultsDatabase.register_statement {| INSERT OR REPLACE INTO procedures -SELECT :pname, :proc_name_hum, :akind, :sfile, :pattr, :cfg +SELECT :pname, :proc_name_hum, :akind, :sfile, :pattr, :cfg, :callees FROM ( SELECT NULL FROM ( @@ -64,7 +64,7 @@ FROM ( OR (attr_kind = :akind AND source_file <= :sfile) )|} -let replace pname pname_blob akind loc_file attr_blob proc_desc = +let replace pname pname_blob akind loc_file attr_blob proc_desc callees = ResultsDatabase.with_registered_statement replace_statement ~f:(fun db replace_stmt -> Sqlite3.bind replace_stmt 1 (* :pname *) pname_blob |> SqliteUtils.check_result_code db ~log:"replace bind pname" ; @@ -79,6 +79,8 @@ let replace pname pname_blob akind loc_file attr_blob proc_desc = |> SqliteUtils.check_result_code db ~log:"replace bind proc attributes" ; Sqlite3.bind replace_stmt 6 (* :cfg *) (Procdesc.SQLite.serialize proc_desc) |> SqliteUtils.check_result_code db ~log:"replace bind cfg" ; + Sqlite3.bind replace_stmt 7 (* :callees *) (Typ.Procname.SQLiteList.serialize callees) + |> SqliteUtils.check_result_code db ~log:"replace bind callees" ; SqliteUtils.result_unit db ~finalize:false ~log:"Attributes.replace" replace_stmt ) @@ -134,6 +136,7 @@ let store ~proc_desc (attr : ProcAttributes.t) = (SourceFile.SQLite.serialize attr.loc.Location.file) (ProcAttributes.SQLite.serialize attr) proc_desc + (Option.map proc_desc ~f:Procdesc.get_static_callees |> Option.value ~default:[]) let load_defined pname = Typ.Procname.SQLite.serialize pname |> find ~defined:true diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index f856acc82..b0305bfe2 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -501,6 +501,18 @@ let fold_instrs pdesc ~init ~f = fold_nodes ~f:fold_node ~init pdesc +let get_static_callees pdesc = + let callees = + fold_instrs pdesc ~init:Typ.Procname.Set.empty ~f:(fun acc _node instr -> + match instr with + | Sil.Call (_, Exp.Const (Const.Cfun callee_pn), _, _, _) -> + Typ.Procname.Set.add callee_pn acc + | _ -> + acc ) + in + Typ.Procname.Set.remove (get_proc_name pdesc) callees |> Typ.Procname.Set.elements + + let find_map_nodes pdesc ~f = List.find_map ~f (get_nodes pdesc) let find_map_instrs pdesc ~f = diff --git a/infer/src/IR/Procdesc.mli b/infer/src/IR/Procdesc.mli index 309490ff7..cdf8bea73 100644 --- a/infer/src/IR/Procdesc.mli +++ b/infer/src/IR/Procdesc.mli @@ -248,6 +248,9 @@ val get_ret_var : t -> Pvar.t val get_start_node : t -> Node.t +val get_static_callees : t -> Typ.Procname.t list +(** get a list of unique static callees excluding self *) + val is_defined : t -> bool (** Return [true] iff the procedure is defined, and not just declared *) diff --git a/infer/src/base/MergeResults.ml b/infer/src/base/MergeResults.ml index 5bd196f32..94046b22e 100644 --- a/infer/src/base/MergeResults.ml +++ b/infer/src/base/MergeResults.ml @@ -16,7 +16,7 @@ let merge_procedures_table ~db_file = Sqlite3.exec db {| INSERT OR REPLACE INTO procedures -SELECT sub.proc_name, sub.proc_name_hum, sub.attr_kind, sub.source_file, sub.proc_attributes, sub.cfg +SELECT sub.proc_name, sub.proc_name_hum, sub.attr_kind, sub.source_file, sub.proc_attributes, sub.cfg, sub.callees FROM ( attached.procedures AS sub LEFT OUTER JOIN procedures AS main diff --git a/infer/src/base/ResultsDatabase.ml b/infer/src/base/ResultsDatabase.ml index 78d6014fb..1f7c29b93 100644 --- a/infer/src/base/ResultsDatabase.ml +++ b/infer/src/base/ResultsDatabase.ml @@ -20,6 +20,7 @@ let procedures_schema = , source_file TEXT NOT NULL , proc_attributes BLOB NOT NULL , cfg BLOB + , callees BLOB NOT NULL )|}