Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 2 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 3 | #include <string.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 12 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 13 | return NULL; |
| 14 | } |
| 15 | |
| 16 | void *Thread2(void *x) { |
| 17 | static volatile int size = 4; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 18 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 19 | memcpy(data+3, data2, size); |
| 20 | return NULL; |
| 21 | } |
| 22 | |
| 23 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 24 | barrier_init(&barrier, 2); |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 25 | print_address("addr=", 1, &data[5]); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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: |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 37 | // CHECK: #0 {{(memcpy|memmove)}} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 38 | // CHECK: #1 Thread2 |
| 39 | // CHECK: Previous write of size 1 at [[ADDR]] by thread T1: |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 40 | // CHECK: #0 {{(memcpy|memmove)}} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 41 | // CHECK: #1 Thread1 |