From 7e7913d5ee15490bfa6236813425b7a91912b96e Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Fri, 19 Oct 2018 03:49:41 -0700 Subject: [PATCH] [racerd] recognize more class member types as concurrency hints for C++ Summary: Even though we recognize the lock/unlock methods of various classes in C++, to report we insist that the class must have a `mutex` member. Equalize the two sets of types recognized. Reviewed By: da319 Differential Revision: D10446527 fbshipit-source-id: f42ae1a35 --- infer/src/concurrency/ConcurrencyModels.ml | 13 +++++++++++++ infer/src/concurrency/ConcurrencyModels.mli | 2 ++ infer/src/concurrency/RacerD.ml | 9 ++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/infer/src/concurrency/ConcurrencyModels.ml b/infer/src/concurrency/ConcurrencyModels.ml index 8954b977e..19e37eca3 100644 --- a/infer/src/concurrency/ConcurrencyModels.ml +++ b/infer/src/concurrency/ConcurrencyModels.ml @@ -41,6 +41,19 @@ let get_thread = function UnknownThread +let cpp_lock_types_matcher = + QualifiedCppName.Match.of_fuzzy_qual_names + [ "apache::thrift::concurrency::ReadWriteMutex" + ; "folly::LockedPtr" + ; "folly::MicroSpinLock" + ; "folly::RWSpinLock" + ; "folly::SharedMutex" + (* NB not impl as in [matcher_lock] as this is just a type, not a call *) + ; "folly::SpinLock" + ; "folly::SpinLockGuard" + ; "std::mutex" ] + + let get_lock = let is_cpp_lock = let matcher_lock = diff --git a/infer/src/concurrency/ConcurrencyModels.mli b/infer/src/concurrency/ConcurrencyModels.mli index 80a1b2172..48ddde83f 100644 --- a/infer/src/concurrency/ConcurrencyModels.mli +++ b/infer/src/concurrency/ConcurrencyModels.mli @@ -34,3 +34,5 @@ val get_current_class_and_annotated_superclasses : val find_annotated_or_overriden_annotated_method : (Annot.Item.t -> bool) -> BuiltinDecl.t -> Tenv.t -> BuiltinDecl.t sexp_option + +val cpp_lock_types_matcher : QualifiedCppName.Match.quals_matcher diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index f2b00decf..b0e4199e5 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -1256,9 +1256,9 @@ let report_unsafe_accesses (aggregated_access_map : ReportMap.t) = in let class_has_mutex_member objc_cpp tenv = let class_name = Typ.Procname.ObjC_Cpp.get_class_type_name objc_cpp in - let matcher = QualifiedCppName.Match.of_fuzzy_qual_names ["std::mutex"] in + let matcher = ConcurrencyModels.cpp_lock_types_matcher in Option.exists (Tenv.lookup tenv class_name) ~f:(fun class_str -> - (* check if the class contains a member of type std::mutex *) + (* check if the class contains a lock member *) List.exists class_str.Typ.Struct.fields ~f:(fun (_, ft, _) -> Option.exists (Typ.name ft) ~f:(fun name -> QualifiedCppName.Match.match_qualifiers matcher (Typ.Name.qual_name name) ) ) ) @@ -1266,9 +1266,8 @@ let report_unsafe_accesses (aggregated_access_map : ReportMap.t) = let should_report {tenv; procdesc} = match Procdesc.get_proc_name procdesc with | Java _ -> - List.exists - ~f:(fun ({threads} : reported_access) -> ThreadsDomain.is_any threads) - grouped_accesses + List.exists grouped_accesses ~f:(fun ({threads} : reported_access) -> + ThreadsDomain.is_any threads ) && should_report_on_proc procdesc tenv | ObjC_Cpp objc_cpp -> (* do not report if a procedure is private *)