[racerd] fix bug in c++ mode

Summary: The contract for reporting races in C++ is to flag races between writes under lock with reads without a lock.  This diff restores that contract which had been violated by recent changes.

Reviewed By: jberdine

Differential Revision: D21383876

fbshipit-source-id: 6a84e1506
master
Nikos Gorogiannis 5 years ago committed by Facebook GitHub Bot
parent 2fefe5ac91
commit 91e0b4c7a0

@ -1013,7 +1013,7 @@ let report_unsafe_accesses ~issue_log classname (aggregated_access_map : ReportM
in in
let report_kind = ReadWriteRace conflict.snapshot in let report_kind = ReadWriteRace conflict.snapshot in
report_thread_safety_violation ~acc ~make_description ~report_kind reported_access ) report_thread_safety_violation ~acc ~make_description ~report_kind reported_access )
| Read _ | ContainerRead _ -> | (Read _ | ContainerRead _) when Procname.is_java pname ->
(* protected read. report unprotected writes and opposite protected writes as conflicts *) (* protected read. report unprotected writes and opposite protected writes as conflicts *)
let can_conflict (snapshot1 : AccessSnapshot.t) (snapshot2 : AccessSnapshot.t) = let can_conflict (snapshot1 : AccessSnapshot.t) (snapshot2 : AccessSnapshot.t) =
if snapshot1.elem.lock && snapshot2.elem.lock then false if snapshot1.elem.lock && snapshot2.elem.lock then false
@ -1032,6 +1032,9 @@ let report_unsafe_accesses ~issue_log classname (aggregated_access_map : ReportM
in in
let report_kind = ReadWriteRace conflict.snapshot in let report_kind = ReadWriteRace conflict.snapshot in
report_thread_safety_violation ~acc ~make_description ~report_kind reported_access ) report_thread_safety_violation ~acc ~make_description ~report_kind reported_access )
| Read _ | ContainerRead _ ->
(* Do not report protected reads for ObjC_Cpp *)
acc
in in
let report_accesses_on_location reportable_accesses init = let report_accesses_on_location reportable_accesses init =
(* Don't report on location if all accesses are on non-concurrent contexts *) (* Don't report on location if all accesses are on non-concurrent contexts *)

@ -39,14 +39,13 @@ class Basic {
int get_suspiciously_read_bad() { return suspiciously_read; } int get_suspiciously_read_bad() { return suspiciously_read; }
void set_suspiciously_written_bad(int new_value) { void set_suspiciously_written_ok(int new_value) {
// the only reason we report here is because of the use of a mutex
mutex_.lock(); mutex_.lock();
mutex_.unlock(); mutex_.unlock();
suspiciously_written = new_value; suspiciously_written = new_value;
} }
int get_suspiciously_written_bad() { int get_suspiciously_written_ok() {
int result; int result;
mutex_.lock(); mutex_.lock();
result = suspiciously_written; result = suspiciously_written;

@ -1,17 +1,11 @@
codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::get_suspiciously_read_bad, 40, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read`,<Write trace>,access to `this->suspiciously_read`] codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::get_suspiciously_read_bad, 40, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read`,<Write trace>,access to `this->suspiciously_read`]
codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::get_suspiciously_written_bad, 52, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_written`,<Write trace>,access to `this->suspiciously_written`] codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::read_double_suspiciously_read_bad, 89, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->single_lock_suspiciously_read`,<Write trace>,access to `this->single_lock_suspiciously_read`]
codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::read_double_suspiciously_read_bad, 90, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->single_lock_suspiciously_read`,<Write trace>,access to `this->single_lock_suspiciously_read`]
codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_abc_bad, 94, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_abc,access to `*(this->x.x2)->a.b.c`,<Write trace>,call to dereferencing::Basic::deref_abc,access to `*(this->x.x2)->a.b.c`] codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_abc_bad, 94, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_abc,access to `*(this->x.x2)->a.b.c`,<Write trace>,call to dereferencing::Basic::deref_abc,access to `*(this->x.x2)->a.b.c`]
codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_abc_bad, 97, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_abc,access to `*(this->x.x2)->a.b.c`,<Write trace>,call to dereferencing::Basic::deref_abc,access to `*(this->x.x2)->a.b.c`]
codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_u_bad, 84, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_u,access to `this->x.x1->u`,<Write trace>,call to dereferencing::Basic::deref_u,access to `this->x.x1->u`] codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_u_bad, 84, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_u,access to `this->x.x1->u`,<Write trace>,call to dereferencing::Basic::deref_u,access to `this->x.x1->u`]
codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_u_bad, 87, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_u,access to `this->x.x1->u`,<Write trace>,call to dereferencing::Basic::deref_u,access to `this->x.x1->u`]
codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_w_bad, 74, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_w,access to `this->x.x1->w`,<Write trace>,call to dereferencing::Basic::deref_w,access to `this->x.x1->w`] codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_w_bad, 74, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_w,access to `this->x.x1->w`,<Write trace>,call to dereferencing::Basic::deref_w,access to `this->x.x1->w`]
codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_w_bad, 77, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to dereferencing::Basic::deref_w,access to `this->x.x1->w`,<Write trace>,call to dereferencing::Basic::deref_w,access to `this->x.x1->w`]
codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp, basics::LockGuardWithScope::FP_suspiciously_written_ok, 47, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_written`,<Write trace>,access to `this->suspiciously_written`]
codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp, basics::LockGuardWithScope::suspiciously_read_bad, 38, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read`,<Write trace>,access to `this->suspiciously_read`] codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp, basics::LockGuardWithScope::suspiciously_read_bad, 38, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read`,<Write trace>,access to `this->suspiciously_read`]
codetoanalyze/cpp/racerd/std_lock.cpp, basics::StdLock::get_bad, 31, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->not_guarded`,<Write trace>,access to `this->not_guarded`] codetoanalyze/cpp/racerd/std_lock.cpp, basics::StdLock::get_bad, 31, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->not_guarded`,<Write trace>,access to `this->not_guarded`]
codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read1_bad, 68, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read1`,<Write trace>,access to `this->suspiciously_read1`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read1_bad, 68, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read1`,<Write trace>,access to `this->suspiciously_read1`]
codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read2_trylock_bad, 92, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read2`,<Write trace>,access to `this->suspiciously_read2`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read2_trylock_bad, 92, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read2`,<Write trace>,access to `this->suspiciously_read2`]
codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read3_deferlock_bad, 107, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read3`,<Write trace>,access to `this->suspiciously_read3`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read3_deferlock_bad, 107, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_read3`,<Write trace>,access to `this->suspiciously_read3`]
codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_written_ok, 78, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->suspiciously_written`,<Write trace>,access to `this->suspiciously_written`]
codetoanalyze/cpp/racerd/without_mutex.cpp, without_mutex::WithoutMutex::get_bad, 15, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->field`,<Write trace>,access to `this->field`] codetoanalyze/cpp/racerd/without_mutex.cpp, without_mutex::WithoutMutex::get_bad, 15, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [<Read trace>,access to `this->field`,<Write trace>,access to `this->field`]

@ -39,7 +39,7 @@ class LockGuardWithScope {
} }
} }
void FP_suspiciously_written_ok(int b, int new_value) { void suspiciously_written_ok(int b, int new_value) {
if (b) { if (b) {
suspiciously_written = new_value; suspiciously_written = new_value;
} else { } else {

Loading…
Cancel
Save