Home | History | Annotate | Download | only in lit_tests
      1 // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
      2 #include <pthread.h>
      3 #include <stddef.h>
      4 #include <stdio.h>
      5 #include <string.h>
      6 #include <unistd.h>
      7 
      8 char *data = new char[10];
      9 char *data1 = new char[10];
     10 char *data2 = new char[10];
     11 
     12 void *Thread1(void *x) {
     13   memcpy(data+5, data1, 1);
     14   return NULL;
     15 }
     16 
     17 void *Thread2(void *x) {
     18   sleep(1);
     19   memcpy(data+3, data2, 4);
     20   return NULL;
     21 }
     22 
     23 int main() {
     24   fprintf(stderr, "addr=%p\n", &data[5]);
     25   pthread_t t[2];
     26   pthread_create(&t[0], NULL, Thread1, NULL);
     27   pthread_create(&t[1], NULL, Thread2, NULL);
     28   pthread_join(t[0], NULL);
     29   pthread_join(t[1], NULL);
     30   return 0;
     31 }
     32 
     33 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
     34 // CHECK: WARNING: ThreadSanitizer: data race
     35 // CHECK:   Write of size 1 at [[ADDR]] by thread T2:
     36 // CHECK:     #0 memcpy
     37 // CHECK:     #1 Thread2
     38 // CHECK:   Previous write of size 1 at [[ADDR]] by thread T1:
     39 // CHECK:     #0 memcpy
     40 // CHECK:     #1 Thread1
     41