Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / Linux / double_race.cpp
blobf02c3c2480cb711396ed9082ebeea5d9971255a9
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2 #include "../test.h"
3 #include <memory.h>
5 // A reproducer for a known issue.
6 // See reference to double_race.cpp in tsan_rtl_report.cpp for an explanation.
8 long long buf[2];
9 volatile int nreport;
11 __attribute__((disable_sanitizer_instrumentation)) void
12 __sanitizer_report_error_summary(const char *summary) {
13 nreport++;
16 const int kEventPCBits = 61;
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);
26 return true;
29 void *Thread(void *arg) {
30 barrier_wait(&barrier);
31 memset(buf, 2, sizeof(buf));
32 return 0;
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;
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