From e993dac233584cdae6275ebee19f755412b3baa1 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 30 Nov 2012 20:02:11 +0000 Subject: [PATCH] tsan: fix int overflow and several instances where tid is used with ignore llvm-svn: 169029 --- compiler-rt/lib/tsan/rtl/tsan_platform.h | 2 +- compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 2 +- compiler-rt/lib/tsan/rtl/tsan_rtl.h | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h b/compiler-rt/lib/tsan/rtl/tsan_platform.h index a9455be..4b7abb5 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_platform.h +++ b/compiler-rt/lib/tsan/rtl/tsan_platform.h @@ -139,7 +139,7 @@ const char *InitializePlatform(); void FinalizePlatform(); void MapThreadTrace(uptr addr, uptr size); uptr ALWAYS_INLINE INLINE GetThreadTrace(int tid) { - uptr p = kTraceMemBegin + tid * kTraceSize * sizeof(Event); + uptr p = kTraceMemBegin + (uptr)tid * kTraceSize * sizeof(Event); DCHECK_LT(p, kTraceMemBegin + kTraceMemSize); return p; } diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index 26ad784..b29fe60 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -359,7 +359,7 @@ static inline bool OldIsInSameSynchEpoch(Shadow old, ThreadState *thr) { } static inline bool HappensBefore(Shadow old, ThreadState *thr) { - return thr->clock.get(old.tid()) >= old.epoch(); + return thr->clock.get(old.TidWithIgnore()) >= old.epoch(); } ALWAYS_INLINE diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index eab2af5..ce43855 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -94,6 +94,11 @@ class FastState { } u64 tid() const { + u64 res = (x_ & ~kIgnoreBit) >> kTidShift; + return res; + } + + u64 TidWithIgnore() const { u64 res = x_ >> kTidShift; return res; } @@ -182,7 +187,7 @@ class Shadow : public FastState { static inline bool TidsAreEqual(const Shadow s1, const Shadow s2) { u64 shifted_xor = (s1.x_ ^ s2.x_) >> kTidShift; - DCHECK_EQ(shifted_xor == 0, s1.tid() == s2.tid()); + DCHECK_EQ(shifted_xor == 0, s1.TidWithIgnore() == s2.TidWithIgnore()); return shifted_xor == 0; } -- 2.7.4