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 | |
| 4 | void *Thread1(void *x) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 5 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 6 | int *p = (int*)x; |
| 7 | p[0] = 1; |
| 8 | return NULL; |
| 9 | } |
| 10 | |
| 11 | void *Thread2(void *x) { |
| 12 | char *p = (char*)x; |
| 13 | p[2] = 1; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 14 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 15 | return NULL; |
| 16 | } |
| 17 | |
| 18 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 19 | barrier_init(&barrier, 2); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 20 | int *data = new int(42); |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 21 | print_address("ptr1=", 1, data); |
| 22 | print_address("ptr2=", 1, (char*)data + 2); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 23 | pthread_t t[2]; |
| 24 | pthread_create(&t[0], NULL, Thread1, data); |
| 25 | pthread_create(&t[1], NULL, Thread2, data); |
| 26 | pthread_join(t[0], NULL); |
| 27 | pthread_join(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 4 at [[PTR1]] by thread T1: |
| 35 | // CHECK: Previous write of size 1 at [[PTR2]] by thread T2: |