aboutsummaryrefslogtreecommitdiff
path: root/contrib/compiler-rt/lib/tsan/go/test.c
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-01-08 19:47:10 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-01-08 19:47:10 +0000
commitf4341a5a66d0fa0f3c9599ea5c5d2d7b2b240c1d (patch)
treef47eabbd2a48be6d6fec3ddeeefae5b4aeb87dbc /contrib/compiler-rt/lib/tsan/go/test.c
parentbbf686ed602a158a5d2fcf9dd90f4bda25feef5e (diff)
parentca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (diff)
Update compiler-rt to trunk r224034. This brings a number of new
builtins, and also the various sanitizers. Support for these will be added in a later commit.
Notes
Notes: svn path=/head/; revision=276851
Diffstat (limited to 'contrib/compiler-rt/lib/tsan/go/test.c')
-rw-r--r--contrib/compiler-rt/lib/tsan/go/test.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/contrib/compiler-rt/lib/tsan/go/test.c b/contrib/compiler-rt/lib/tsan/go/test.c
new file mode 100644
index 000000000000..94433f1b8c22
--- /dev/null
+++ b/contrib/compiler-rt/lib/tsan/go/test.c
@@ -0,0 +1,65 @@
+//===-- test.c ------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Sanity test for Go runtime.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+void __tsan_init(void **thr, void (*cb)(void*));
+void __tsan_fini();
+void __tsan_map_shadow(void *addr, unsigned long size);
+void __tsan_go_start(void *thr, void **chthr, void *pc);
+void __tsan_go_end(void *thr);
+void __tsan_read(void *thr, void *addr, void *pc);
+void __tsan_write(void *thr, void *addr, void *pc);
+void __tsan_func_enter(void *thr, void *pc);
+void __tsan_func_exit(void *thr);
+void __tsan_malloc(void *p, unsigned long sz);
+void __tsan_acquire(void *thr, void *addr);
+void __tsan_release(void *thr, void *addr);
+void __tsan_release_merge(void *thr, void *addr);
+
+void symbolize_cb(void *ctx) {}
+
+char buf0[100<<10];
+
+void foobar() {}
+void barfoo() {}
+
+int main(void) {
+ void *thr0 = 0;
+ char *buf = (char*)((unsigned long)buf0 + (64<<10) - 1 & ~((64<<10) - 1));
+ __tsan_malloc(buf, 10);
+ __tsan_init(&thr0, symbolize_cb);
+ __tsan_map_shadow(buf, 4096);
+ __tsan_func_enter(thr0, (char*)&main + 1);
+ __tsan_malloc(buf, 10);
+ __tsan_release(thr0, buf);
+ __tsan_release_merge(thr0, buf);
+ void *thr1 = 0;
+ __tsan_go_start(thr0, &thr1, (char*)&barfoo + 1);
+ void *thr2 = 0;
+ __tsan_go_start(thr0, &thr2, (char*)&barfoo + 1);
+ __tsan_func_enter(thr1, (char*)&foobar + 1);
+ __tsan_func_enter(thr1, (char*)&foobar + 1);
+ __tsan_write(thr1, buf, (char*)&barfoo + 1);
+ __tsan_acquire(thr1, buf);
+ __tsan_func_exit(thr1);
+ __tsan_func_exit(thr1);
+ __tsan_go_end(thr1);
+ __tsan_func_enter(thr2, (char*)&foobar + 1);
+ __tsan_read(thr2, buf, (char*)&barfoo + 1);
+ __tsan_func_exit(thr2);
+ __tsan_go_end(thr2);
+ __tsan_func_exit(thr0);
+ __tsan_fini();
+ return 0;
+}