Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 2 | // This test fails on powerpc64 (VMA=46). |
| 3 | // The size of the write reported by Tsan for T1 is 8 instead of 1. |
| 4 | // XFAIL: powerpc64 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 5 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 6 | |
| 7 | pthread_mutex_t Mtx; |
| 8 | int Global; |
| 9 | |
| 10 | void *Thread1(void *x) { |
| 11 | pthread_mutex_init(&Mtx, 0); |
| 12 | pthread_mutex_lock(&Mtx); |
| 13 | Global = 42; |
| 14 | pthread_mutex_unlock(&Mtx); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 15 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 16 | return NULL; |
| 17 | } |
| 18 | |
| 19 | void *Thread2(void *x) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 20 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 21 | pthread_mutex_lock(&Mtx); |
| 22 | Global = 43; |
| 23 | pthread_mutex_unlock(&Mtx); |
| 24 | return NULL; |
| 25 | } |
| 26 | |
| 27 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 28 | barrier_init(&barrier, 2); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 29 | pthread_t t[2]; |
| 30 | pthread_create(&t[0], NULL, Thread1, NULL); |
| 31 | pthread_create(&t[1], NULL, Thread2, NULL); |
| 32 | pthread_join(t[0], NULL); |
| 33 | pthread_join(t[1], NULL); |
| 34 | pthread_mutex_destroy(&Mtx); |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | // CHECK: WARNING: ThreadSanitizer: data race |
| 39 | // CHECK-NEXT: Atomic read of size 1 at {{.*}} by thread T2: |
| 40 | // CHECK-NEXT: #0 pthread_mutex_lock |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 41 | // CHECK-NEXT: #1 Thread2{{.*}} {{.*}}race_on_mutex.c:21{{(:3)?}} ({{.*}}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 42 | // CHECK: Previous write of size 1 at {{.*}} by thread T1: |
| 43 | // CHECK-NEXT: #0 pthread_mutex_init {{.*}} ({{.*}}) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 44 | // CHECK-NEXT: #1 Thread1{{.*}} {{.*}}race_on_mutex.c:11{{(:3)?}} ({{.*}}) |