[ASan] Add references to the issue tracker about malloc/free/new/delete mismatch...
[blocksruntime.git] / test / tsan / oob_race.cc
blob16c59c678a5882ba0cafa111582040d948e7ac66
1 // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <unistd.h>
6 const long kOffset = 64*1024;
8 void *Thread(void *p) {
9 sleep(1);
10 ((char*)p)[-kOffset] = 43;
11 return 0;
14 int main() {
15 char *volatile p0 = new char[16];
16 delete[] p0;
17 char *p = new char[32];
18 pthread_t th;
19 pthread_create(&th, 0, Thread, p);
20 p[-kOffset] = 42;
21 pthread_join(th, 0);
24 // Used to crash with CHECK failed.
25 // CHECK: WARNING: ThreadSanitizer: data race