From 25a688bdbeb67f46b292634577718c8b90a1a2b3 Mon Sep 17 00:00:00 2001 From: Peter O'Hearn Date: Thu, 20 Oct 2016 12:00:54 -0700 Subject: [PATCH] [threadsafety] Consider certain init() methods as constructors Reviewed By: jvillard Differential Revision: D4046903 fbshipit-source-id: 0183b0c --- infer/src/checkers/ThreadSafety.ml | 10 ++++------ infer/src/opensource/FbThreadSafety.ml | 12 ++++++++++++ infer/src/opensource/FbThreadSafety.mli | 12 ++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 infer/src/opensource/FbThreadSafety.ml create mode 100644 infer/src/opensource/FbThreadSafety.mli diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 4c0bda291..142940d53 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -7,11 +7,6 @@ * of patent rights can be found in the PATENTS file in the same directory. *) -(** I want to use various powersets instead of just variables like Var.Set - For example to track the analogues of attributes - I will do this running forwards later, but backwards for now. -*) - open! Utils module F = Format @@ -109,7 +104,8 @@ module ResultsTableType = Map.Make (struct let compare (_, _, pn1, _) (_,_,pn2,_) = Procname.compare pn1 pn2 end) -let should_analyze_proc (_,_,proc_name,proc_desc) = +let should_analyze_proc (_,tenv,proc_name,proc_desc) = + not (FbThreadSafety.is_custom_init tenv proc_name) && not (Procname.java_is_autogen_method proc_name) && not (Procname.is_constructor proc_name) && not (Procname.is_class_initializer proc_name) && @@ -132,6 +128,7 @@ let make_results_table file_env = in map_post_computation_over_procs compute_post_for_procedure procs_to_analyze + let report_thread_safety_errors ( _, tenv, pname, pdesc) writestate = let report_one_error access_path = let description = @@ -148,6 +145,7 @@ let report_thread_safety_errors ( _, tenv, pname, pdesc) writestate = in IList.iter report_one_error (IList.map snd (PathDomain.elements writestate)) + (* For now, just checks if there is one active element amongst the posts of the analyzed methods. This indicates that the method races with itself. To be refined later. *) let process_results_table tab = diff --git a/infer/src/opensource/FbThreadSafety.ml b/infer/src/opensource/FbThreadSafety.ml new file mode 100644 index 000000000..00d3f1fec --- /dev/null +++ b/infer/src/opensource/FbThreadSafety.ml @@ -0,0 +1,12 @@ +(* + * 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 + +let is_custom_init _ _ = false diff --git a/infer/src/opensource/FbThreadSafety.mli b/infer/src/opensource/FbThreadSafety.mli new file mode 100644 index 000000000..fdd84f323 --- /dev/null +++ b/infer/src/opensource/FbThreadSafety.mli @@ -0,0 +1,12 @@ +(* + * 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 + +val is_custom_init : Tenv.t -> Procname.t -> bool