[ThreadSafety] Releasing lock at the end of the procedure if it has a lock_guard field.

Reviewed By: sblackshear

Differential Revision: D5255450

fbshipit-source-id: ff43c2a
master
Daiva Naudziuniene 8 years ago committed by Facebook Github Bot
parent e87e2b007d
commit 336b7182c3

@ -910,7 +910,18 @@ let analyze_procedure { Callbacks.proc_desc; tenv; summary; } =
let return_attributes =
try AttributeMapDomain.find return_var_ap attribute_map
with Not_found -> AttributeSetDomain.empty in
let post = thumbs_up, threads, locks, accesses, return_attributes in
(* A hack for modeling lock_guard by releasing a
lock at the end of the procedure, as destructors are not modeled yet *)
let update_locks = match Procdesc.get_proc_name proc_desc with
| ObjC_Cpp _ when locks ->
let matcher = QualifiedCppName.Match.of_fuzzy_qual_names ["std::lock_guard"] in
(* Unlock, if the procedure contains a local field of type std::lock_guard *)
not (List.exists (Procdesc.get_locals proc_desc) ~f:(fun (_, ft) ->
Option.exists (Typ.name ft) ~f:(fun name ->
QualifiedCppName.Match.match_qualifiers matcher (Typ.Name.qual_name name))
))
| _ -> locks in
let post = thumbs_up, threads, update_locks, accesses, return_attributes in
Summary.update_summary post summary
| None ->
summary

@ -6,5 +6,6 @@ codetoanalyze/cpp/threadsafety/basics_with_mutex.cpp, basics::BasicsWithHeader_g
codetoanalyze/cpp/threadsafety/lock_guard.cpp, basics::LockGuard_get2, 3, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `suspiciously_written`,<Beginning of write trace>,access to `suspiciously_written`]
codetoanalyze/cpp/threadsafety/lock_guard.cpp, basics::LockGuard_get3, 0, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `not_guarded`,<Beginning of write trace>,access to `not_guarded`]
codetoanalyze/cpp/threadsafety/lock_guard.cpp, basics::LockGuard_get4, 0, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `suspiciously_read`,<Beginning of write trace>,access to `suspiciously_read`]
codetoanalyze/cpp/threadsafety/lock_guard.cpp, basics::LockGuard_test1, 2, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `suspiciously_read`,<Beginning of write trace>,access to `suspiciously_read`]
codetoanalyze/cpp/threadsafety/lock_guard_with_scope.cpp, basics::LockGuardWithScope_get3, 0, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `not_guarded`,<Beginning of write trace>,access to `not_guarded`]
codetoanalyze/cpp/threadsafety/lock_guard_with_scope.cpp, basics::LockGuardWithScope_get4, 0, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `suspiciously_read`,<Beginning of write trace>,access to `suspiciously_read`]

@ -41,6 +41,11 @@ class LockGuard {
int get4() { return suspiciously_read; }
int test1() {
int result = get1();
return suspiciously_read + result;
}
private:
int well_guarded;
int suspiciously_read;

Loading…
Cancel
Save