[ThreadSafety] Do not report if all accesses are unprotected.

Reviewed By: jberdine

Differential Revision: D5256183

fbshipit-source-id: f2f2c57
master
Daiva Naudziuniene 8 years ago committed by Facebook Github Bot
parent 4ce997c8f0
commit 0a786e9019

@ -1215,11 +1215,16 @@ let report_unsafe_accesses aggregated_access_map =
(* protected write, do nothing *)
reported_acc
| Access.Read, AccessPrecondition.Unprotected _ ->
(* unprotected read. report all writes as conflicts *)
(* unprotected read. report all writes as conflicts for java *)
(* for c++ filter out unprotected writes *)
let is_cpp_protected_write pre = match pre with
| AccessPrecondition.Unprotected _ -> Typ.Procname.is_java pname
| AccessPrecondition.Protected _ -> true in
let all_writes =
List.filter
~f:(fun (other_access, _, other_threaded, _, _) ->
TraceElem.is_write other_access && not (threaded && other_threaded))
~f:(fun (other_access, pre, other_threaded, _, _) ->
TraceElem.is_write other_access && not (threaded && other_threaded)
&& is_cpp_protected_write pre)
accesses in
if List.is_empty all_writes
then

@ -1,32 +0,0 @@
/*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <mutex>
namespace basics {
class BasicsWithHeader {
public:
BasicsWithHeader(){};
void set(int new_value) {
field_1 = new_value;
field_2 = new_value;
field_3 = new_value;
};
int get1() { return field_1; };
int get2() { return field_2; };
private:
int field_1;
int field_2;
int field_3;
std::mutex mutex_;
};
}

@ -1,10 +1,6 @@
codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get2, 3, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `suspiciously_written`,<Beginning of write trace>,access to `suspiciously_written`]
codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get3, 0, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `not_guarded`,<Beginning of write trace>,access to `not_guarded`]
codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get4, 0, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `suspiciously_read`,<Beginning of write trace>,access to `suspiciously_read`]
codetoanalyze/cpp/threadsafety/basics_with_mutex.cpp, basics::BasicsWithHeader_get1, 0, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `field_1`,<Beginning of write trace>,access to `field_1`]
codetoanalyze/cpp/threadsafety/basics_with_mutex.cpp, basics::BasicsWithHeader_get2, 0, THREAD_SAFETY_VIOLATION, [<Beginning of read trace>,access to `field_2`,<Beginning of write trace>,access to `field_2`]
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`]

Loading…
Cancel
Save