1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s 2 #include "../test.h" 3 #include <memory.h> 4 5 // A reproducer for a known issue. 6 // See reference to double_race.cpp in tsan_rtl_report.cpp for an explanation. 7 8 long long buf[2]; 9 volatile int nreport; 10 11 __attribute__((disable_sanitizer_instrumentation)) void 12 __sanitizer_report_error_summary(const char *summary) { 13 nreport++; 14 } 15 16 const int kEventPCBits = 61; 17 18 extern "C" __attribute__((disable_sanitizer_instrumentation)) bool 19 __tsan_symbolize_external(unsigned long pc, char *func_buf, 20 unsigned long func_siz, char *file_buf, 21 unsigned long file_siz, int *line, int *col) { 22 if (pc >> kEventPCBits) { 23 printf("bad PC passed to __tsan_symbolize_external: %lx\n", pc); 24 _exit(1); 25 } 26 return true; 27 } 28 29 void *Thread(void *arg) { 30 barrier_wait(&barrier); 31 memset(buf, 2, sizeof(buf)); 32 return 0; 33 } 34 35 int main() { 36 barrier_init(&barrier, 2); 37 pthread_t t; 38 pthread_create(&t, 0, Thread, 0); 39 memset(buf, 1, sizeof(buf)); 40 barrier_wait(&barrier); 41 pthread_join(t, 0); 42 return 0; 43 } 44 45 // CHECK: WARNING: ThreadSanitizer: data race 46 // CHECK: Write of size 8 at {{.*}} by thread T1: 47 // CHECK: #0 memset 48 // CHECK: #{{[12]}} Thread 49 // CHECK-NOT: bad PC passed to __tsan_symbolize_external 50 // CHECK-NOT: __sanitizer_report_error_summary 51 // CHECK-NOT: WARNING: ThreadSanitizer: data race 52