1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 #include "test.h" 3 #include <string.h> 4 5 char *data = new char[10]; 6 char *data1 = new char[10]; 7 char *data2 = new char[10]; 8 9 void *Thread1(void *x) { 10 static volatile int size = 1; 11 memcpy(data+5, data1, size); 12 barrier_wait(&barrier); 13 return NULL; 14 } 15 16 void *Thread2(void *x) { 17 static volatile int size = 4; 18 barrier_wait(&barrier); 19 memcpy(data+3, data2, size); 20 return NULL; 21 } 22 23 int main() { 24 barrier_init(&barrier, 2); 25 print_address("addr=", 1, &data[5]); 26 pthread_t t[2]; 27 pthread_create(&t[0], NULL, Thread1, NULL); 28 pthread_create(&t[1], NULL, Thread2, NULL); 29 pthread_join(t[0], NULL); 30 pthread_join(t[1], NULL); 31 return 0; 32 } 33 34 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]] 35 // CHECK: WARNING: ThreadSanitizer: data race 36 // CHECK: Write of size 1 at [[ADDR]] by thread T2: 37 // CHECK: #0 {{(memcpy|memmove)}} 38 // CHECK: #1 Thread2 39 // CHECK: Previous write of size 1 at [[ADDR]] by thread T1: 40 // CHECK: #0 {{(memcpy|memmove)}} 41 // CHECK: #1 Thread1 42