forked from OSchip/llvm-project
tsan: remember 2 stack frames for atomics (caller and atomic itself)
llvm-svn: 174167
This commit is contained in:
parent
4b866274c3
commit
aa6af4ddd1
|
|
@ -20,25 +20,41 @@
|
||||||
// http://www.hpl.hp.com/personal/Hans_Boehm/c++mm/
|
// http://www.hpl.hp.com/personal/Hans_Boehm/c++mm/
|
||||||
|
|
||||||
#include "sanitizer_common/sanitizer_placement_new.h"
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
||||||
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
||||||
#include "tsan_interface_atomic.h"
|
#include "tsan_interface_atomic.h"
|
||||||
#include "tsan_flags.h"
|
#include "tsan_flags.h"
|
||||||
#include "tsan_rtl.h"
|
#include "tsan_rtl.h"
|
||||||
|
|
||||||
using namespace __tsan; // NOLINT
|
using namespace __tsan; // NOLINT
|
||||||
|
|
||||||
|
#define SCOPED_ATOMIC(func, ...) \
|
||||||
|
const uptr callpc = (uptr)__builtin_return_address(0); \
|
||||||
|
const uptr pc = __sanitizer::StackTrace::GetCurrentPc(); \
|
||||||
|
mo = ConvertOrder(mo); \
|
||||||
|
mo = flags()->force_seq_cst_atomics ? (morder)mo_seq_cst : mo; \
|
||||||
|
ThreadState *const thr = cur_thread(); \
|
||||||
|
AtomicStatInc(thr, sizeof(*a), mo, StatAtomic##func); \
|
||||||
|
ScopedAtomic sa(thr, callpc, __FUNCTION__); \
|
||||||
|
return Atomic##func(thr, pc, __VA_ARGS__); \
|
||||||
|
/**/
|
||||||
|
|
||||||
class ScopedAtomic {
|
class ScopedAtomic {
|
||||||
public:
|
public:
|
||||||
ScopedAtomic(ThreadState *thr, uptr pc, const char *func)
|
ScopedAtomic(ThreadState *thr, uptr pc, const char *func)
|
||||||
: thr_(thr) {
|
: thr_(thr) {
|
||||||
CHECK_EQ(thr_->in_rtl, 1); // 1 due to our own ScopedInRtl member.
|
CHECK_EQ(thr_->in_rtl, 0);
|
||||||
|
ProcessPendingSignals(thr);
|
||||||
|
FuncEntry(thr_, pc);
|
||||||
DPrintf("#%d: %s\n", thr_->tid, func);
|
DPrintf("#%d: %s\n", thr_->tid, func);
|
||||||
|
thr_->in_rtl++;
|
||||||
}
|
}
|
||||||
~ScopedAtomic() {
|
~ScopedAtomic() {
|
||||||
CHECK_EQ(thr_->in_rtl, 1);
|
thr_->in_rtl--;
|
||||||
|
CHECK_EQ(thr_->in_rtl, 0);
|
||||||
|
FuncExit(thr_);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
ThreadState *thr_;
|
ThreadState *thr_;
|
||||||
ScopedInRtl in_rtl_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Some shortcuts.
|
// Some shortcuts.
|
||||||
|
|
@ -212,17 +228,6 @@ a128 func_cas(volatile a128 *v, a128 cmp, a128 xch) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SCOPED_ATOMIC(func, ...) \
|
|
||||||
mo = ConvertOrder(mo); \
|
|
||||||
mo = flags()->force_seq_cst_atomics ? (morder)mo_seq_cst : mo; \
|
|
||||||
ThreadState *const thr = cur_thread(); \
|
|
||||||
ProcessPendingSignals(thr); \
|
|
||||||
const uptr pc = (uptr)__builtin_return_address(0); \
|
|
||||||
AtomicStatInc(thr, sizeof(*a), mo, StatAtomic##func); \
|
|
||||||
ScopedAtomic sa(thr, pc, __FUNCTION__); \
|
|
||||||
return Atomic##func(thr, pc, __VA_ARGS__); \
|
|
||||||
/**/
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static int SizeLog() {
|
static int SizeLog() {
|
||||||
if (sizeof(T) <= 1)
|
if (sizeof(T) <= 1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue