1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
3
4void *Thread1(void *x) {
5 int *p = (int*)x;
6 p[0] = 1;
7 barrier_wait(barrier: &barrier);
8 return NULL;
9}
10
11void *Thread2(void *x) {
12 barrier_wait(barrier: &barrier);
13 char *p = (char*)x;
14 p[2] = 1;
15 return NULL;
16}
17
18int main() {
19 barrier_init(barrier: &barrier, count: 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(newthread: &t[0], NULL, start_routine: Thread1, arg: data);
25 pthread_create(newthread: &t[1], NULL, start_routine: Thread2, arg: data);
26 pthread_join(th: t[0], NULL);
27 pthread_join(th: 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 1 at [[PTR2]] by thread T2:
35// CHECK: Previous write of size 4 at [[PTR1]] by thread T1:
36

source code of compiler-rt/test/tsan/mop_with_offset.cpp