1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include <stdio.h>
3 
4 // Defined by tsan.
5 extern "C" void *__interceptor_malloc(unsigned long size);
6 extern "C" void __interceptor_free(void *p);
7 
malloc(unsigned long size)8 extern "C" void *malloc(unsigned long size) {
9   static int first = 0;
10   if (__sync_lock_test_and_set(&first, 1) == 0)
11     fprintf(stderr, "user malloc\n");
12   return __interceptor_malloc(size);
13 }
14 
free(void * p)15 extern "C" void free(void *p) {
16   __interceptor_free(p);
17 }
18 
main()19 int main() {
20   volatile char *p = (char*)malloc(10);
21   p[0] = 0;
22   free((void*)p);
23 }
24 
25 // CHECK: user malloc
26 // CHECK-NOT: ThreadSanitizer
27 
28