[liveness] remove special-casing for destructor reads

Reviewed By: jeremydubreil

Differential Revision: D6569310

fbshipit-source-id: f072e05
master
Sam Blackshear 7 years ago committed by Facebook Github Bot
parent f37344358b
commit d6ed9e3bbe

@ -56,10 +56,6 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| Sil.Load (lhs_id, _, _, _) when Ident.is_none lhs_id -> | Sil.Load (lhs_id, _, _, _) when Ident.is_none lhs_id ->
(* dummy deref inserted by frontend--don't count as a read *) (* dummy deref inserted by frontend--don't count as a read *)
astate 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, _, _) -> | Sil.Load (lhs_id, rhs_exp, _, _) ->
Domain.remove (Var.of_id lhs_id) astate |> exp_add_live rhs_exp Domain.remove (Var.of_id lhs_id) astate |> exp_add_live rhs_exp
| Sil.Store (Lvar lhs_pvar, _, rhs_exp, _) -> | Sil.Store (Lvar lhs_pvar, _, rhs_exp, _) ->
@ -95,23 +91,7 @@ let matcher_scope_guard =
| _ -> | _ ->
init init
in in
let default_scope_guards = let default_scope_guards = ["CKComponentScope"] in
[ (* 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
of_json default_scope_guards Config.cxx_scope_guards of_json default_scope_guards Config.cxx_scope_guards
|> QualifiedCppName.Match.of_fuzzy_qual_names |> QualifiedCppName.Match.of_fuzzy_qual_names
@ -180,3 +160,4 @@ let checker {Callbacks.tenv; summary; proc_desc} : Specs.summary =
in in
List.iter (CFG.nodes cfg) ~f:report_on_node ; List.iter (CFG.nodes cfg) ~f:report_on_node ;
summary summary

@ -15,17 +15,6 @@ namespace infer {
class ScopeGuard {}; class ScopeGuard {};
}; // namespace infer }; // namespace infer
namespace folly {
class ScopeGuard {};
class SharedMutex {
public:
class ReadHolder {};
class WriteHolder {};
};
} // namespace folly
namespace dead_stores { namespace dead_stores {
void easy_bad() { int x = 5; } void easy_bad() { int x = 5; }
@ -296,15 +285,6 @@ int* sentinel_ptr_ok(int* j) {
return i; 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; } void custom_scope_guard_ok() { infer::ScopeGuard guard; }
struct S { struct S {
@ -319,7 +299,7 @@ S mk_s() {
}; };
// s gets read by the destructor for 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 // need to handle operator= in order to detect this case
void FN_dead_struct_value2_bad() { void FN_dead_struct_value2_bad() {
@ -339,6 +319,10 @@ B& struct_rvalue_ref_used_ok() {
return b; return b;
} }
struct NoDestructor {};
void dead_struct_no_destructor_bad() { NoDestructor dead; }
std::mutex my_mutex; std::mutex my_mutex;
void dead_lock_guard_ok() { std::lock_guard<std::mutex> lock(my_mutex); } void dead_lock_guard_ok() { std::lock_guard<std::mutex> lock(my_mutex); }

@ -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::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_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_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::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::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_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::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_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_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] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus3_bad, 2, DEAD_STORE, [Write of unused value]

Loading…
Cancel
Save