[llvm-commits] [compiler-rt] r164010 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_stackdepot.cc tests/sanitizer_stackdepot_test.cc

Dmitry Vyukov dvyukov at google.com
Sun Sep 16 20:14:15 PDT 2012


Author: dvyukov
Date: Sun Sep 16 22:14:15 2012
New Revision: 164010

URL: http://llvm.org/viewvc/llvm-project?rev=164010&view=rev
Log:
tsan: reserve msb in stack depot id's (required for msan)

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc?rev=164010&r1=164009&r2=164010&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc Sun Sep 16 22:14:15 2012
@@ -13,14 +13,15 @@
 
 #include "sanitizer_stackdepot.h"
 #include "sanitizer_common.h"
+#include "sanitizer_internal_defs.h"
 #include "sanitizer_mutex.h"
 #include "sanitizer_atomic.h"
 
 namespace __sanitizer {
 
 const int kTabSize = 1024 * 1024;  // Hash table size.
-const int kPartBits = 10;
-const int kPartShift = sizeof(u32) * 8 - kPartBits;
+const int kPartBits = 8;
+const int kPartShift = sizeof(u32) * 8 - kPartBits - 1;
 const int kPartCount = 1 << kPartBits;  // Number of subparts in the table.
 const int kPartSize = kTabSize / kPartCount;
 const int kMaxId = 1 << kPartShift;
@@ -157,6 +158,8 @@
   id = atomic_fetch_add(&depot.seq[part], 1, memory_order_relaxed) + 1;
   CHECK_LT(id, kMaxId);
   id |= part << kPartShift;
+  CHECK_NE(id, 0);
+  CHECK_EQ(id & (1u << 31), 0);
   s = allocDesc(size);
   s->id = id;
   s->hash = h;
@@ -170,6 +173,7 @@
 const uptr *StackDepotGet(u32 id, uptr *size) {
   if (id == 0)
     return 0;
+  CHECK_EQ(id & (1u << 31), 0);
   // High kPartBits contain part id, so we need to scan at most kPartSize lists.
   uptr part = id >> kPartShift;
   for (int i = 0; i != kPartSize; i++) {

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc?rev=164010&r1=164009&r2=164010&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc Sun Sep 16 22:14:15 2012
@@ -29,7 +29,7 @@
 
 TEST(SanitizerCommon, StackDepotAbsent) {
   uptr sz1 = 0;
-  const uptr *sp1 = StackDepotGet(-10, &sz1);
+  const uptr *sp1 = StackDepotGet((1 << 30) - 1, &sz1);
   EXPECT_EQ(sp1, (uptr*)0);
 }
 





More information about the llvm-commits mailing list