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
8char buf[16];
9volatile int nreport;
10
11void __sanitizer_report_error_summary(const char *summary) {
12 nreport++;
13}
14
15const int kEventPCBits = 61;
16
17extern "C" bool __tsan_symbolize_external(unsigned long pc, char *func_buf,
18 unsigned long func_siz,
19 char *file_buf,
20 unsigned long file_siz, int *line,
21 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 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: WARNING: ThreadSanitizer: data race
51// CHECK: Write of size 8 at {{.*}} by thread T1:
52// CHECK: #0 Thread
53