summaryrefslogtreecommitdiff
path: root/test/lsan
diff options
context:
space:
mode:
authorSergey Matveev <earthdok@google.com>2014-12-05 00:10:15 +0000
committerSergey Matveev <earthdok@google.com>2014-12-05 00:10:15 +0000
commitd6e5390b3d0e57cfac7b27457a4c1ba2a3366e34 (patch)
tree550e3f065faca832af61b54f932827c4bbb5c321 /test/lsan
parentb89adc423d3a6214c09ce2bf71720cf5053d4016 (diff)
[ASan, LSan] Improve tracking of thread creation.
In the current scheme of things, the call to ThreadStart() in the child thread is not synchronized with the parent thread. So, if a pointer is passed to pthread_create, there may be a window of time during which this pointer will not be discoverable by LSan. I.e. the pthread_create interceptor has already returneed and thus the pointer is no longer on the parent stack, but we don't yet know the location of the child stack. This has caused bogus leak reports (see http://llvm.org/bugs/show_bug.cgi?id=21621/). This patch makes the pthread_create interceptor wait until the child thread is properly registered before returning. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223419 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/lsan')
-rw-r--r--test/lsan/TestCases/leak_check_before_thread_started.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/lsan/TestCases/leak_check_before_thread_started.cc b/test/lsan/TestCases/leak_check_before_thread_started.cc
new file mode 100644
index 000000000..a2357e0f3
--- /dev/null
+++ b/test/lsan/TestCases/leak_check_before_thread_started.cc
@@ -0,0 +1,15 @@
+// Regression test for http://llvm.org/bugs/show_bug.cgi?id=21621
+// This test relies on timing between threads, so any failures will be flaky.
+// RUN: LSAN_BASE="use_stacks=0:use_registers=0"
+// RUN: %clangxx_lsan %s -std=c++11 -o %t
+// RUN: %run %t
+#include <thread>
+#include <chrono>
+
+void func() {
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+}
+
+int main() {
+ std::thread(func).detach();
+}