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