[ASan/Win] Don't crash when ASAN_OPTIONS have disable_core=1
[blocksruntime.git] / test / tsan / race_on_heap.cc
blob54c4a9b02f9404765e47a19b1ada8816302e0007
1 // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdlib.h>
4 #include <stdio.h>
6 void *Thread1(void *p) {
7 *(int*)p = 42;
8 return 0;
11 void *Thread2(void *p) {
12 *(int*)p = 44;
13 return 0;
16 void *alloc() {
17 return malloc(99);
20 void *AllocThread(void* arg) {
21 return alloc();
24 int main() {
25 void *p = 0;
26 pthread_t t[2];
27 pthread_create(&t[0], 0, AllocThread, 0);
28 pthread_join(t[0], &p);
29 fprintf(stderr, "addr=%p\n", p);
30 pthread_create(&t[0], 0, Thread1, (char*)p + 16);
31 pthread_create(&t[1], 0, Thread2, (char*)p + 16);
32 pthread_join(t[0], 0);
33 pthread_join(t[1], 0);
34 return 0;
37 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
38 // CHECK: WARNING: ThreadSanitizer: data race
39 // ...
40 // CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread T1:
41 // CHCEKL #0 malloc
42 // CHECK: #{{1|2}} alloc
43 // CHECK: #{{2|3}} AllocThread
44 // ...
45 // CHECK: Thread T1 (tid={{.*}}, finished) created by main thread at:
46 // CHECK: #0 pthread_create
47 // CHECK: #1 main