summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Posix/deep_thread_stack.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-08-05 16:48:12 +0000
committerNico Weber <nicolasweber@gmx.de>2019-08-05 16:48:12 +0000
commit2f91f4f955190c500ab3a1ec4b92ad3f3af72724 (patch)
tree14f3bb241fe04d56481582cad0dcb00f3dc1a01e /test/asan/TestCases/Posix/deep_thread_stack.cpp
parent9b46f1e9a77b1faa2e9869b9b886f05ac5d39411 (diff)
downloadcompiler-rt-2f91f4f955190c500ab3a1ec4b92ad3f3af72724.tar.gz
compiler-rt: Rename cc files below test/asan to cpp
See r367803 and similar other changes. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@367887 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan/TestCases/Posix/deep_thread_stack.cpp')
-rw-r--r--test/asan/TestCases/Posix/deep_thread_stack.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/asan/TestCases/Posix/deep_thread_stack.cpp b/test/asan/TestCases/Posix/deep_thread_stack.cpp
new file mode 100644
index 000000000..535da79ff
--- /dev/null
+++ b/test/asan/TestCases/Posix/deep_thread_stack.cpp
@@ -0,0 +1,58 @@
+// RUN: %clangxx_asan -O0 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O1 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// REQUIRES: stable-runtime
+
+#include <pthread.h>
+
+int *x;
+
+void *AllocThread(void *arg) {
+ x = new int;
+ *x = 42;
+ return NULL;
+}
+
+void *FreeThread(void *arg) {
+ delete x;
+ return NULL;
+}
+
+void *AccessThread(void *arg) {
+ *x = 43; // BOOM
+ return NULL;
+}
+
+typedef void* (*callback_type)(void* arg);
+
+void *RunnerThread(void *function) {
+ pthread_t thread;
+ pthread_create(&thread, NULL, (callback_type)function, NULL);
+ pthread_join(thread, NULL);
+ return NULL;
+}
+
+void RunThread(callback_type function) {
+ pthread_t runner;
+ pthread_create(&runner, NULL, RunnerThread, (void*)function);
+ pthread_join(runner, NULL);
+}
+
+int main(int argc, char *argv[]) {
+ RunThread(AllocThread);
+ RunThread(FreeThread);
+ RunThread(AccessThread);
+ return (x != 0);
+}
+
+// CHECK: AddressSanitizer: heap-use-after-free
+// CHECK: WRITE of size 4 at 0x{{.*}} thread T[[ACCESS_THREAD:[0-9]+]]
+// CHECK: freed by thread T[[FREE_THREAD:[0-9]+]] here:
+// CHECK: previously allocated by thread T[[ALLOC_THREAD:[0-9]+]] here:
+// CHECK: Thread T[[ACCESS_THREAD]] created by T[[ACCESS_RUNNER:[0-9]+]] here:
+// CHECK: Thread T[[ACCESS_RUNNER]] created by T0 here:
+// CHECK: Thread T[[FREE_THREAD]] created by T[[FREE_RUNNER:[0-9]+]] here:
+// CHECK: Thread T[[FREE_RUNNER]] created by T0 here:
+// CHECK: Thread T[[ALLOC_THREAD]] created by T[[ALLOC_RUNNER:[0-9]+]] here:
+// CHECK: Thread T[[ALLOC_RUNNER]] created by T0 here: