]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/tsan/mop_with_offset2.cc
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / test / tsan / mop_with_offset2.cc
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
3
4 void *Thread1(void *x) {
5 barrier_wait(&barrier);
6 int *p = (int*)x;
7 p[0] = 1;
8 return NULL;
9 }
10
11 void *Thread2(void *x) {
12 char *p = (char*)x;
13 p[2] = 1;
14 barrier_wait(&barrier);
15 return NULL;
16 }
17
18 int main() {
19 barrier_init(&barrier, 2);
20 int *data = new int(42);
21 fprintf(stderr, "ptr1=%p\n", data);
22 fprintf(stderr, "ptr2=%p\n", (char*)data + 2);
23 pthread_t t[2];
24 pthread_create(&t[0], NULL, Thread1, data);
25 pthread_create(&t[1], NULL, Thread2, data);
26 pthread_join(t[0], NULL);
27 pthread_join(t[1], NULL);
28 delete data;
29 }
30
31 // CHECK: ptr1=[[PTR1:0x[0-9,a-f]+]]
32 // CHECK: ptr2=[[PTR2:0x[0-9,a-f]+]]
33 // CHECK: WARNING: ThreadSanitizer: data race
34 // CHECK: Write of size 4 at [[PTR1]] by thread T1:
35 // CHECK: Previous write of size 1 at [[PTR2]] by thread T2: