From c081cef5a5cd26e706c84eab98eb610d02f430f8 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 6 Oct 2017 03:44:00 -0700 Subject: [PATCH] [thread-safety][c++] Skip folly::detail::SingletonHolder::createInstance Summary: The analyzer currently does not understand the control flow of Singletons, which leads to false alarms. This diff is an unsound hack that simply ignores any read or write accesses made when computing the value of a singleton. Reviewed By: sblackshear Differential Revision: D5979639 fbshipit-source-id: 34caecb --- infer/src/checkers/ThreadSafety.ml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 55ca1099f..82eb7390f 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -534,6 +534,16 @@ module TransferFunctions (CFG : ProcCfg.S) = struct ; return_ownership= OwnershipAbstractValue.unowned ; return_attributes= AttributeSetDomain.empty } + let cpp_force_skipped = + let matcher = + ( lazy + (QualifiedCppName.Match.of_fuzzy_qual_names ["folly::detail::SingletonHolder::createInstance"]) + ) + in + fun pname -> + QualifiedCppName.Match.match_qualifiers (Lazy.force matcher) + (Typ.Procname.get_qualifiers pname) + let get_summary caller_pdesc callee_pname actuals callee_loc tenv = let get_receiver_ap actuals = match List.hd actuals with @@ -544,13 +554,15 @@ module TransferFunctions (CFG : ProcCfg.S) = struct "Call to %a is marked as a container write, but has no receiver" Typ.Procname.pp callee_pname in - match get_container_access callee_pname tenv with - | Some ContainerWrite + match (get_container_access callee_pname tenv, callee_pname) with + | Some ContainerWrite, _ -> make_container_access callee_pname ~is_write:true (get_receiver_ap actuals) callee_loc tenv - | Some ContainerRead + | Some ContainerRead, _ -> make_container_access callee_pname ~is_write:false (get_receiver_ap actuals) callee_loc tenv - | None + | None, Typ.Procname.ObjC_Cpp _ when cpp_force_skipped callee_pname + -> None + | None, _ -> Summary.read_summary caller_pdesc callee_pname (* return true if the given procname boxes a primitive type into a reference type *)