summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/tsan/libcxx/std_shared_ptr.cc
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-05-13 22:30:16 +0000
committerAlexey Samsonov <samsonov@google.com>2014-05-13 22:30:16 +0000
commit5716928ae2203f6ede337db2c7d86dc906a91027 (patch)
tree649b49eec29f328df2ed72c50c1e2b4663a287a7 /compiler-rt/test/tsan/libcxx/std_shared_ptr.cc
parent060ca7596c254a14b9cb2528d993087175f21b59 (diff)
downloadbcm5719-llvm-5716928ae2203f6ede337db2c7d86dc906a91027.tar.gz
bcm5719-llvm-5716928ae2203f6ede337db2c7d86dc906a91027.zip
[TSan] Build TSan-instrumented version of libcxx and use it in lit tests.
TSan can produce false positives in code that uses C++11 threading, as it doesn't see synchronization inside standard library. See http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-February/035408.html for an example of such case. We may build custom TSan-instrumented version libcxx to fight with that. This change adds build rules for libcxx_tsan and integrates it into testing infrastructure. llvm-svn: 208737
Diffstat (limited to 'compiler-rt/test/tsan/libcxx/std_shared_ptr.cc')
-rw-r--r--compiler-rt/test/tsan/libcxx/std_shared_ptr.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler-rt/test/tsan/libcxx/std_shared_ptr.cc b/compiler-rt/test/tsan/libcxx/std_shared_ptr.cc
new file mode 100644
index 00000000000..191a17cc798
--- /dev/null
+++ b/compiler-rt/test/tsan/libcxx/std_shared_ptr.cc
@@ -0,0 +1,24 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include <stdio.h>
+#include <memory>
+#include <thread>
+
+int main() {
+ int v1 = 0;
+ int v2 = 0;
+ std::thread t1;
+ std::thread t2;
+
+ {
+ auto thingy = std::make_shared<int>(42);
+ t1 = std::thread([thingy, &v1] { v1 = *thingy; });
+ t2 = std::thread([thingy, &v2] { v2 = *thingy; });
+ }
+
+ t1.join();
+ t2.join();
+ printf("%d %d\n", v1, v2);
+ // CHECK-NOT: ThreadSanitizer: data race
+ // CHECK: 42 42
+ return 0;
+}
OpenPOWER on IntegriCloud