summaryrefslogtreecommitdiff
path: root/test/tsan/mop_with_offset2.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-08-02 07:18:07 +0000
committerFangrui Song <maskray@google.com>2019-08-02 07:18:07 +0000
commit681afdf34bb16d1877e984d157dfd389a79a4256 (patch)
tree4e3f851ec5cfff68846a11843577ed58d4fdd430 /test/tsan/mop_with_offset2.cpp
parent871e3822d6679af8f7cfa763b65258e47f2d8d69 (diff)
downloadcompiler-rt-681afdf34bb16d1877e984d157dfd389a79a4256.tar.gz
compiler-rt: Rename .cc file in test/tsan to .cpp
Like r367463, but for test/tsan. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@367656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/mop_with_offset2.cpp')
-rw-r--r--test/tsan/mop_with_offset2.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/tsan/mop_with_offset2.cpp b/test/tsan/mop_with_offset2.cpp
new file mode 100644
index 000000000..73c53f512
--- /dev/null
+++ b/test/tsan/mop_with_offset2.cpp
@@ -0,0 +1,35 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "test.h"
+
+void *Thread1(void *x) {
+ barrier_wait(&barrier);
+ int *p = (int*)x;
+ p[0] = 1;
+ return NULL;
+}
+
+void *Thread2(void *x) {
+ char *p = (char*)x;
+ p[2] = 1;
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ int *data = new int(42);
+ print_address("ptr1=", 1, data);
+ print_address("ptr2=", 1, (char*)data + 2);
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread1, data);
+ pthread_create(&t[1], NULL, Thread2, data);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+ delete data;
+}
+
+// CHECK: ptr1=[[PTR1:0x[0-9,a-f]+]]
+// CHECK: ptr2=[[PTR2:0x[0-9,a-f]+]]
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 4 at [[PTR1]] by thread T1:
+// CHECK: Previous write of size 1 at [[PTR2]] by thread T2: