[compiler-rt] r212531 - tsan: fix a bug in metamap
Dmitry Vyukov
dvyukov at google.com
Tue Jul 8 06:28:01 PDT 2014
Author: dvyukov
Date: Tue Jul 8 08:28:01 2014
New Revision: 212531
URL: http://llvm.org/viewvc/llvm-project?rev=212531&view=rev
Log:
tsan: fix a bug in metamap
The bug happens in the following case:
Mutex is located at heap block beginning,
when we call MutexDestroy, s->next is set to 0,
so free can't find the MBlock related to the block.
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc
compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc?rev=212531&r1=212530&r2=212531&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_sync.cc Tue Jul 8 08:28:01 2014
@@ -46,7 +46,6 @@ void SyncVar::Reset() {
is_recursive = 0;
is_broken = 0;
is_linker_init = 0;
- next = 0;
clock.Zero();
read_clock.Reset();
Modified: compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc?rev=212531&r1=212530&r2=212531&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc (original)
+++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc Tue Jul 8 08:28:01 2014
@@ -108,4 +108,16 @@ TEST(MetaMap, MoveMemory) {
m->FreeRange(thr, 0, (uptr)&block2[0], 4 * sizeof(u64));
}
+TEST(MetaMap, ResetSync) {
+ ThreadState *thr = cur_thread();
+ MetaMap *m = &ctx->metamap;
+ u64 block[1] = {}; // fake malloc block
+ m->AllocBlock(thr, 0, (uptr)&block[0], 1 * sizeof(u64));
+ SyncVar *s = m->GetOrCreateAndLock(thr, 0, (uptr)&block[0], true);
+ s->Reset();
+ s->mtx.Unlock();
+ uptr sz = m->FreeBlock(thr, 0, (uptr)&block[0]);
+ EXPECT_EQ(sz, 1 * sizeof(u64));
+}
+
} // namespace __tsan
More information about the llvm-commits
mailing list