blob: 6c2defc835a633062f385720c3d11ba5871c267e [file] [log] [blame]
Stephen Hines6a211c52014-07-21 00:49:56 -07001// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
Stephen Hines2d1fdb22014-05-28 23:58:16 -07002#include <pthread.h>
3#include <stdlib.h>
4#include <stdio.h>
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08005#include "test.h"
Stephen Hines2d1fdb22014-05-28 23:58:16 -07006
7void *Thread1(void *p) {
8 *(int*)p = 42;
9 return 0;
10}
11
12void *Thread2(void *p) {
13 *(int*)p = 44;
14 return 0;
15}
16
17void *alloc() {
18 return malloc(99);
19}
20
21void *AllocThread(void* arg) {
22 return alloc();
23}
24
25int main() {
26 void *p = 0;
27 pthread_t t[2];
28 pthread_create(&t[0], 0, AllocThread, 0);
29 pthread_join(t[0], &p);
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080030 print_address("addr=", 1, p);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070031 pthread_create(&t[0], 0, Thread1, (char*)p + 16);
32 pthread_create(&t[1], 0, Thread2, (char*)p + 16);
33 pthread_join(t[0], 0);
34 pthread_join(t[1], 0);
35 return 0;
36}
37
38// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
39// CHECK: WARNING: ThreadSanitizer: data race
40// ...
41// CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread T1:
Stephen Hines6a211c52014-07-21 00:49:56 -070042// CHCEK: #0 malloc
Stephen Hines2d1fdb22014-05-28 23:58:16 -070043// CHECK: #{{1|2}} alloc
44// CHECK: #{{2|3}} AllocThread
45// ...
46// CHECK: Thread T1 (tid={{.*}}, finished) created by main thread at:
47// CHECK: #0 pthread_create
48// CHECK: #1 main