Summary: This is a minimal change to (poorly) recognize and model std::mutex lock and unlock methods, and to surface all thread safety issues for C++ based on the computed summaries with no filtering. This ignores much of the Java analysis, including everything about the Threads domain. The S/N is comically low at this point. Reviewed By: sblackshear Differential Revision: D5120485 fbshipit-source-id: 0f08caamaster
parent
b4b45236fd
commit
bf504c5b70
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2016 - 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.
|
||||
|
||||
TESTS_DIR = ../../..
|
||||
|
||||
ANALYZER = checkers
|
||||
# see explanations in cpp/errors/Makefile for the custom isystem
|
||||
CLANG_OPTIONS = -x c++ -std=c++11 -nostdinc++ -isystem$(ROOT_DIR) -isystem$(CLANG_INCLUDES)/c++/v1/ -c
|
||||
INFER_OPTIONS = --threadsafety --ml-buckets cpp --no-filtering --debug-exceptions --project-root $(TESTS_DIR) --no-failures-allowed
|
||||
INFER_OPTIONS += --debug
|
||||
INFERPRINT_OPTIONS = --issues-tests
|
||||
|
||||
SOURCES = $(wildcard *.cpp)
|
||||
|
||||
include $(TESTS_DIR)/clang.make
|
||||
|
||||
infer-out/report.json: $(MAKEFILE_LIST)
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 Basic {
|
||||
public:
|
||||
Basic() {}
|
||||
|
||||
void set(int new_value) {
|
||||
not_guarded = new_value;
|
||||
mutex_.lock();
|
||||
well_guarded = new_value;
|
||||
suspiciously_read = new_value;
|
||||
mutex_.unlock();
|
||||
suspiciously_written = new_value;
|
||||
}
|
||||
|
||||
int get1() {
|
||||
int result;
|
||||
mutex_.lock();
|
||||
result = well_guarded;
|
||||
mutex_.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
int get2() {
|
||||
int result;
|
||||
mutex_.lock();
|
||||
result = suspiciously_written;
|
||||
mutex_.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
int get3() { return not_guarded; }
|
||||
|
||||
int get4() { return suspiciously_read; }
|
||||
|
||||
private:
|
||||
int well_guarded;
|
||||
int suspiciously_read;
|
||||
int suspiciously_written;
|
||||
int not_guarded;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get2, 3, THREAD_SAFETY_VIOLATION, [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.cpp, basics::Basic_set, 1, THREAD_SAFETY_VIOLATION, [access to `not_guarded`]
|
||||
codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_set, 6, THREAD_SAFETY_VIOLATION, [access to `suspiciously_written`]
|
Loading…
Reference in new issue