Fix flakiness in the analysis when a procedure is defined in more than one file.

Reviewed By: jberdine

Differential Revision: D3804399

fbshipit-source-id: e347927
master
Cristiano Calcagno 8 years ago committed by Facebook Github Bot 4
parent 55f854f1b4
commit 20c33f15c9

@ -250,7 +250,6 @@ let module Node = {
NodeSet.elements (slice_nodes node.nd_preds) NodeSet.elements (slice_nodes node.nd_preds)
}; };
let get_exn node => node.nd_exn; let get_exn node => node.nd_exn;
let set_proc_desc node proc => node.nd_proc = Some proc;
/** Get the proc desc of the node */ /** Get the proc desc of the node */
let get_proc_desc node => let get_proc_desc node =>

@ -259,9 +259,6 @@ let module Node: {
/** Set the source location of the node */ /** Set the source location of the node */
let set_loc: t => Location.t => unit; let set_loc: t => Location.t => unit;
/** Set the proc desc associated to the node */
let set_proc_desc: t => Procdesc.t => unit;
/** Set the successor nodes and exception nodes, and build predecessor links */ /** Set the successor nodes and exception nodes, and build predecessor links */
let set_succs_exn: cfg => t => list t => list t => unit; let set_succs_exn: cfg => t => list t => list t => unit;
}; };

@ -54,11 +54,8 @@ let analyze_exe_env exe_env => {
/** Create an exe_env from a cluster. */ /** Create an exe_env from a cluster. */
let exe_env_from_cluster cluster => { let exe_env_from_cluster cluster => {
let _exe_env = Exe_env.create (); let _exe_env = Exe_env.create ();
let source_dirs = [cluster]; ignore (Exe_env.add_cg _exe_env cluster);
let sorted_dirs = IList.sort DB.source_dir_compare source_dirs; Exe_env.freeze _exe_env
IList.iter (fun src_dir => ignore (Exe_env.add_cg _exe_env src_dir)) sorted_dirs;
let exe_env = Exe_env.freeze _exe_env;
exe_env
}; };

@ -1288,8 +1288,9 @@ let init_files format_list_by_kind => {
let init_files_of_report_kind (report_kind, format_list) => { let init_files_of_report_kind (report_kind, format_list) => {
let init_files_of_format (format_kind, outfile) => let init_files_of_format (format_kind, outfile) =>
switch (format_kind, report_kind) { switch (format_kind, report_kind) {
| (Csv, Stats) => Report.pp_header outfile.fmt ()
| (Csv, Issues) => IssuesCsv.pp_header outfile.fmt () | (Csv, Issues) => IssuesCsv.pp_header outfile.fmt ()
| (Csv, Procs) => ProcsCsv.pp_header outfile.fmt ()
| (Csv, Stats) => Report.pp_header outfile.fmt ()
| (Json, Issues) => IssuesJson.pp_json_open outfile.fmt () | (Json, Issues) => IssuesJson.pp_json_open outfile.fmt ()
| (Xml, Issues) => IssuesXml.pp_issues_open outfile.fmt () | (Xml, Issues) => IssuesXml.pp_issues_open outfile.fmt ()
| (Xml, Procs) => ProcsXml.pp_procs_open outfile.fmt () | (Xml, Procs) => ProcsXml.pp_procs_open outfile.fmt ()

@ -82,17 +82,27 @@ let add_cg (exe_env: t) (source_dir : DB.source_dir) =
Cg.extend exe_env.cg cg; Cg.extend exe_env.cg cg;
let file_data = new_file_data source nLOC cg_fname in let file_data = new_file_data source nLOC cg_fname in
let defined_procs = Cg.get_defined_nodes cg in let defined_procs = Cg.get_defined_nodes cg in
IList.iter (fun pname ->
let should_update = (* Find the file where `pname` is defined according to the attributes,
if Procname.Hash.mem exe_env.proc_map pname then if a cfg for that file exist. *)
let old_source = let defined_in_according_to_attributes pname =
(Procname.Hash.find exe_env.proc_map pname).source in match AttributesTable.load_attributes pname with
(* when a procedure is defined in several files, *) | None ->
(* map to the first alphabetically *) None
source < old_source | Some proc_attributes ->
else true in let loc = proc_attributes.ProcAttributes.loc in
if should_update let source_file = loc.Location.file in
then Procname.Hash.replace exe_env.proc_map pname file_data) let source_dir = DB.source_dir_from_source_file source_file in
let cfg_fname = DB.source_dir_get_internal_file source_dir ".cfg" in
let cfg_fname_exists = Sys.file_exists (DB.filename_to_string cfg_fname) in
if cfg_fname_exists
then Some source_file
else None in
IList.iter
(fun pname ->
if (defined_in_according_to_attributes pname = None)
then Procname.Hash.replace exe_env.proc_map pname file_data)
defined_procs; defined_procs;
Some cg Some cg

Loading…
Cancel
Save