diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index 30014059b..ae88ab32f 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -1013,7 +1013,7 @@ let report_unsafe_accesses ~issue_log classname (aggregated_access_map : ReportM in let report_kind = ReadWriteRace conflict.snapshot in 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 *) let can_conflict (snapshot1 : AccessSnapshot.t) (snapshot2 : AccessSnapshot.t) = 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 let report_kind = ReadWriteRace conflict.snapshot in report_thread_safety_violation ~acc ~make_description ~report_kind reported_access ) + | Read _ | ContainerRead _ -> + (* Do not report protected reads for ObjC_Cpp *) + acc in let report_accesses_on_location reportable_accesses init = (* Don't report on location if all accesses are on non-concurrent contexts *) diff --git a/infer/tests/codetoanalyze/cpp/racerd/basics.cpp b/infer/tests/codetoanalyze/cpp/racerd/basics.cpp index dc8b7dd83..e45c83a5d 100644 --- a/infer/tests/codetoanalyze/cpp/racerd/basics.cpp +++ b/infer/tests/codetoanalyze/cpp/racerd/basics.cpp @@ -39,14 +39,13 @@ class Basic { int get_suspiciously_read_bad() { return suspiciously_read; } - void set_suspiciously_written_bad(int new_value) { - // the only reason we report here is because of the use of a mutex + void set_suspiciously_written_ok(int new_value) { mutex_.lock(); mutex_.unlock(); suspiciously_written = new_value; } - int get_suspiciously_written_bad() { + int get_suspiciously_written_ok() { int result; mutex_.lock(); result = suspiciously_written; diff --git a/infer/tests/codetoanalyze/cpp/racerd/issues.exp b/infer/tests/codetoanalyze/cpp/racerd/issues.exp index ddc3276b6..674b497be 100644 --- a/infer/tests/codetoanalyze/cpp/racerd/issues.exp +++ b/infer/tests/codetoanalyze/cpp/racerd/issues.exp @@ -1,17 +1,11 @@ codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::get_suspiciously_read_bad, 40, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->suspiciously_read`,,access to `this->suspiciously_read`] -codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::get_suspiciously_written_bad, 52, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->suspiciously_written`,,access to `this->suspiciously_written`] -codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::read_double_suspiciously_read_bad, 90, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->single_lock_suspiciously_read`,,access to `this->single_lock_suspiciously_read`] +codetoanalyze/cpp/racerd/basics.cpp, basics::Basic::read_double_suspiciously_read_bad, 89, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->single_lock_suspiciously_read`,,access to `this->single_lock_suspiciously_read`] codetoanalyze/cpp/racerd/dereferencing.cpp, dereferencing::Basic::deref_abc_bad, 94, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,call to dereferencing::Basic::deref_abc,access to `*(this->x.x2)->a.b.c`,,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, [,call to dereferencing::Basic::deref_abc,access to `*(this->x.x2)->a.b.c`,,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, [,call to dereferencing::Basic::deref_u,access to `this->x.x1->u`,,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, [,call to dereferencing::Basic::deref_u,access to `this->x.x1->u`,,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, [,call to dereferencing::Basic::deref_w,access to `this->x.x1->w`,,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, [,call to dereferencing::Basic::deref_w,access to `this->x.x1->w`,,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, [,access to `this->suspiciously_written`,,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, [,access to `this->suspiciously_read`,,access to `this->suspiciously_read`] codetoanalyze/cpp/racerd/std_lock.cpp, basics::StdLock::get_bad, 31, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->not_guarded`,,access to `this->not_guarded`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read1_bad, 68, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->suspiciously_read1`,,access to `this->suspiciously_read1`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read2_trylock_bad, 92, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->suspiciously_read2`,,access to `this->suspiciously_read2`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_read3_deferlock_bad, 107, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->suspiciously_read3`,,access to `this->suspiciously_read3`] -codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock::suspiciously_written_ok, 78, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->suspiciously_written`,,access to `this->suspiciously_written`] codetoanalyze/cpp/racerd/without_mutex.cpp, without_mutex::WithoutMutex::get_bad, 15, LOCK_CONSISTENCY_VIOLATION, no_bucket, WARNING, [,access to `this->field`,,access to `this->field`] diff --git a/infer/tests/codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp b/infer/tests/codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp index 6ea944878..0b51f92a4 100644 --- a/infer/tests/codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp +++ b/infer/tests/codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp @@ -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) { suspiciously_written = new_value; } else {