[PATCH] D31354: [tsan] Assert to make sure we don't try to Acquire() or Release() a NULL pointer

Kuba (Brecka) Mracek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 14:08:12 PDT 2017


kubamracek created this revision.

This will provide much better diagnostics when we try to Acquire(NULL) or Release(NULL).  I've been recently debugging such a bug and this would have helped tremendously.


https://reviews.llvm.org/D31354

Files:
  lib/tsan/rtl/tsan_rtl_mutex.cc


Index: lib/tsan/rtl/tsan_rtl_mutex.cc
===================================================================
--- lib/tsan/rtl/tsan_rtl_mutex.cc
+++ lib/tsan/rtl/tsan_rtl_mutex.cc
@@ -361,6 +361,7 @@
 
 void Acquire(ThreadState *thr, uptr pc, uptr addr) {
   DPrintf("#%d: Acquire %zx\n", thr->tid, addr);
+  CHECK(addr && "addr must not be NULL");
   if (thr->ignore_sync)
     return;
   SyncVar *s = ctx->metamap.GetIfExistsAndLock(addr, false);
@@ -390,6 +391,7 @@
 
 void Release(ThreadState *thr, uptr pc, uptr addr) {
   DPrintf("#%d: Release %zx\n", thr->tid, addr);
+  CHECK(addr && "addr must not be NULL");
   if (thr->ignore_sync)
     return;
   SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
@@ -402,6 +404,7 @@
 
 void ReleaseStore(ThreadState *thr, uptr pc, uptr addr) {
   DPrintf("#%d: ReleaseStore %zx\n", thr->tid, addr);
+  CHECK(addr && "addr must not be NULL");
   if (thr->ignore_sync)
     return;
   SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31354.93006.patch
Type: text/x-patch
Size: 1009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170324/da5ce24a/attachment.bin>


More information about the llvm-commits mailing list