summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/tsan/oob_race.cc
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/test/tsan/oob_race.cc')
-rw-r--r--compiler-rt/test/tsan/oob_race.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/compiler-rt/test/tsan/oob_race.cc b/compiler-rt/test/tsan/oob_race.cc
new file mode 100644
index 00000000000..c84e819cbe7
--- /dev/null
+++ b/compiler-rt/test/tsan/oob_race.cc
@@ -0,0 +1,26 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+
+const long kOffset = 64*1024;
+
+void *Thread(void *p) {
+ sleep(1);
+ ((char*)p)[-kOffset] = 43;
+ return 0;
+}
+
+int main() {
+ char *volatile p0 = new char[16];
+ delete[] p0;
+ char *p = new char[32];
+ pthread_t th;
+ pthread_create(&th, 0, Thread, p);
+ p[-kOffset] = 42;
+ pthread_join(th, 0);
+}
+
+// Used to crash with CHECK failed.
+// CHECK: WARNING: ThreadSanitizer: data race
+
OpenPOWER on IntegriCloud