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 *)