1 // RUN: %clangxx_tsan -O1 %s -o %t && %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 8 extern "C" void *malloc(unsigned long size) { 9 static int first = 0; 10 if (__sync_lock_test_and_set(&first, 1) == 0) 11 printf("user malloc\n"); 12 return __interceptor_malloc(size); 13 } 14 15 extern "C" void free(void *p) { 16 __interceptor_free(p); 17 } 18 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