From d6ed9e3bbe5ad828149c4249408e21d9abb00d90 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Thu, 14 Dec 2017 15:48:52 -0800 Subject: [PATCH] [liveness] remove special-casing for destructor reads Reviewed By: jeremydubreil Differential Revision: D6569310 fbshipit-source-id: f072e05 --- infer/src/checkers/liveness.ml | 23 ++-------------- .../cpp/liveness/dead_stores.cpp | 26 ++++--------------- .../codetoanalyze/cpp/liveness/issues.exp | 4 +-- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/infer/src/checkers/liveness.ml b/infer/src/checkers/liveness.ml index fbdd0af31..b7b038408 100644 --- a/infer/src/checkers/liveness.ml +++ b/infer/src/checkers/liveness.ml @@ -56,10 +56,6 @@ module TransferFunctions (CFG : ProcCfg.S) = struct | Sil.Load (lhs_id, _, _, _) when Ident.is_none lhs_id -> (* dummy deref inserted by frontend--don't count as a read *) astate - | Sil.Call (_, Exp.Const Cfun (Typ.Procname.ObjC_Cpp _ as pname), _, _, _) - when Typ.Procname.is_destructor pname -> - (* don't count destructor calls as a read *) - astate | Sil.Load (lhs_id, rhs_exp, _, _) -> Domain.remove (Var.of_id lhs_id) astate |> exp_add_live rhs_exp | Sil.Store (Lvar lhs_pvar, _, rhs_exp, _) -> @@ -95,23 +91,7 @@ let matcher_scope_guard = | _ -> init in - let default_scope_guards = - [ (* C++ *) - "folly::RWSpinLock::ReadHolder" - ; "folly::RWSpinLock::WriteHolder" - ; "folly::ScopeGuard" - ; "folly::SharedMutex::ReadHolder" - ; "folly::SharedMutex::WriteHolder" - ; "folly::SharedMutexReadPriority::ReadHolder" - ; "folly::SharedMutexReadPriority::WriteHolder" - ; "folly::SharedMutexWritePriority::ReadHolder" - ; "folly::SharedMutexWritePriority::WriteHolder" - ; "folly::SpinLockGuard" - ; "std::lock_guard" - ; "std::scoped_lock" - ; "std::unique_lock" (* Obj-C *) - ; "CKComponentScope" ] - in + let default_scope_guards = ["CKComponentScope"] in of_json default_scope_guards Config.cxx_scope_guards |> QualifiedCppName.Match.of_fuzzy_qual_names @@ -180,3 +160,4 @@ let checker {Callbacks.tenv; summary; proc_desc} : Specs.summary = in List.iter (CFG.nodes cfg) ~f:report_on_node ; summary + diff --git a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp index cd2c3e22b..60e997838 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp +++ b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp @@ -15,17 +15,6 @@ namespace infer { class ScopeGuard {}; }; // namespace infer -namespace folly { -class ScopeGuard {}; - -class SharedMutex { - public: - class ReadHolder {}; - class WriteHolder {}; -}; - -} // namespace folly - namespace dead_stores { void easy_bad() { int x = 5; } @@ -296,15 +285,6 @@ int* sentinel_ptr_ok(int* j) { return i; } -void scope_guard_ok() { - // realistically, it would be something like guard = folly::makeGuard(); - folly::ScopeGuard guard; -} - -void read_holder_ok() { folly::SharedMutex::ReadHolder guard; } - -void write_holder_ok() { folly::SharedMutex::WriteHolder guard; } - void custom_scope_guard_ok() { infer::ScopeGuard guard; } struct S { @@ -319,7 +299,7 @@ S mk_s() { }; // s gets read by the destructor for S -void dead_struct_value1_bad() { S s = mk_s(); } +void FN_dead_struct_value1_bad() { S s = mk_s(); } // need to handle operator= in order to detect this case void FN_dead_struct_value2_bad() { @@ -339,6 +319,10 @@ B& struct_rvalue_ref_used_ok() { return b; } +struct NoDestructor {}; + +void dead_struct_no_destructor_bad() { NoDestructor dead; } + std::mutex my_mutex; void dead_lock_guard_ok() { std::lock_guard lock(my_mutex); } diff --git a/infer/tests/codetoanalyze/cpp/liveness/issues.exp b/infer/tests/codetoanalyze/cpp/liveness/issues.exp index c780f20dc..427cbed44 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/issues.exp +++ b/infer/tests/codetoanalyze/cpp/liveness/issues.exp @@ -1,12 +1,12 @@ codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::FP_assign_array_tricky_ok, 3, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_pointer_bad, 2, DEAD_STORE, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_struct_no_destructor_bad, 0, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_struct_rvalue_ref_bad, 0, DEAD_STORE, [Write of unused value] -codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_struct_value1_bad, 0, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_then_live_bad, 1, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::easy_bad, 0, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_capture_no_call_bad, 1, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_capture_reassign_bad, 1, DEAD_STORE, [Write of unused value] -codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::lambda_bad::lambda_dead_stores.cpp:164:11_operator(), 1, DEAD_STORE, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::lambda_bad::lambda_dead_stores.cpp:153:11_operator(), 1, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus1_bad, 2, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus2_bad, 2, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus3_bad, 2, DEAD_STORE, [Write of unused value]