[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / mop_with_offset.cc
blob2b6a4ff50aaf1ba99d48c02d164d98512e9e044d
1 // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stddef.h>
4 #include <stdio.h>
5 #include <unistd.h>
7 void *Thread1(void *x) {
8 int *p = (int*)x;
9 p[0] = 1;
10 return NULL;
13 void *Thread2(void *x) {
14 sleep(1);
15 char *p = (char*)x;
16 p[2] = 1;
17 return NULL;
20 int main() {
21 int *data = new int(42);
22 fprintf(stderr, "ptr1=%p\n", data);
23 fprintf(stderr, "ptr2=%p\n", (char*)data + 2);
24 pthread_t t[2];
25 pthread_create(&t[0], NULL, Thread1, data);
26 pthread_create(&t[1], NULL, Thread2, data);
27 pthread_join(t[0], NULL);
28 pthread_join(t[1], NULL);
29 delete data;
32 // CHECK: ptr1=[[PTR1:0x[0-9,a-f]+]]
33 // CHECK: ptr2=[[PTR2:0x[0-9,a-f]+]]
34 // CHECK: WARNING: ThreadSanitizer: data race
35 // CHECK: Write of size 1 at [[PTR2]] by thread T2:
36 // CHECK: Previous write of size 4 at [[PTR1]] by thread T1: