[PATCH] D14826: [tsan] Replace new/delete with a local variable in ThreadSpecificDtors unit test

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 09:12:30 PST 2015


kubabrecka created this revision.
kubabrecka added reviewers: dvyukov, kcc, samsonov, glider.
kubabrecka added subscribers: llvm-commits, zaks.anna, ismailp.

On OS X, this unit test (ThreadSpecificDtors) fails, because the `new` and `delete` operators actually call the overridden operators, which end up using TLVs and crash.  Since C++'s `new` and `delete` is not important in this test, let's just replace them with a local variable.  This fixes the test on OS X.

http://reviews.llvm.org/D14826

Files:
  lib/tsan/tests/rtl/tsan_posix.cc

Index: lib/tsan/tests/rtl/tsan_posix.cc
===================================================================
--- lib/tsan/tests/rtl/tsan_posix.cc
+++ lib/tsan/tests/rtl/tsan_posix.cc
@@ -35,7 +35,7 @@
   __tsan_write4(&k->cnt);
   EXPECT_EQ(pthread_mutex_unlock(k->mtx), 0);
   if (k->val == 42) {
-    delete k;
+    // Okay.
   } else if (k->val == 43 || k->val == 44) {
     k->val--;
     EXPECT_EQ(pthread_setspecific(k->key, k), 0);
@@ -57,14 +57,13 @@
   pthread_mutex_t mtx;
   EXPECT_EQ(pthread_mutex_init(&mtx, 0), 0);
   pthread_t th[3];
-  thread_key *k[3];
-  k[0] = new thread_key(key, &mtx, 42, &cnt);
-  k[1] = new thread_key(key, &mtx, 43, &cnt);
-  k[2] = new thread_key(key, &mtx, 44, &cnt);
-  EXPECT_EQ(pthread_create(&th[0], 0, dtors_thread, k[0]), 0);
-  EXPECT_EQ(pthread_create(&th[1], 0, dtors_thread, k[1]), 0);
+  thread_key k1 = thread_key(key, &mtx, 42, &cnt);
+  thread_key k2 = thread_key(key, &mtx, 43, &cnt);
+  thread_key k3 = thread_key(key, &mtx, 44, &cnt);
+  EXPECT_EQ(pthread_create(&th[0], 0, dtors_thread, &k1), 0);
+  EXPECT_EQ(pthread_create(&th[1], 0, dtors_thread, &k2), 0);
   EXPECT_EQ(pthread_join(th[0], 0), 0);
-  EXPECT_EQ(pthread_create(&th[2], 0, dtors_thread, k[2]), 0);
+  EXPECT_EQ(pthread_create(&th[2], 0, dtors_thread, &k3), 0);
   EXPECT_EQ(pthread_join(th[1], 0), 0);
   EXPECT_EQ(pthread_join(th[2], 0), 0);
   EXPECT_EQ(pthread_key_delete(key), 0);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14826.40661.patch
Type: text/x-patch
Size: 1412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151119/726af699/attachment.bin>


More information about the llvm-commits mailing list