brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · f02c3c2 Raw
52 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s2#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 8long long buf[2];9volatile int nreport;10 11__attribute__((disable_sanitizer_instrumentation)) void12__sanitizer_report_error_summary(const char *summary) {13  nreport++;14}15 16const int kEventPCBits = 61;17 18extern "C" __attribute__((disable_sanitizer_instrumentation)) bool19__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 29void *Thread(void *arg) {30  barrier_wait(&barrier);31  memset(buf, 2, sizeof(buf));32  return 0;33}34 35int 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 race46// CHECK:   Write of size 8 at {{.*}} by thread T1:47// CHECK:     #0 {{.*}}memset48// CHECK:     #{{[12]}} Thread49// CHECK-NOT: bad PC passed to __tsan_symbolize_external50// CHECK-NOT: __sanitizer_report_error_summary51// CHECK-NOT: WARNING: ThreadSanitizer: data race52