1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
3 
Thread1(void * x)4 void *Thread1(void *x) {
5   barrier_wait(&barrier);
6   int *p = (int*)x;
7   p[0] = 1;
8   return NULL;
9 }
10 
Thread2(void * x)11 void *Thread2(void *x) {
12   char *p = (char*)x;
13   p[2] = 1;
14   barrier_wait(&barrier);
15   return NULL;
16 }
17 
main()18 int main() {
19   barrier_init(&barrier, 2);
20   int *data = new int(42);
21   print_address("ptr1=", 1, data);
22   print_address("ptr2=", 1, (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:
36