annotate compiler-rt/test/tsan/flush_memory.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents c4bab56944e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
1 // RUN: %clangxx_tsan -O1 %s -o %t
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
2 // RUN: %env_tsan_opts=flush_memory_ms=1:flush_symbolizer_ms=1:memory_limit_mb=1 not %run %t 2>&1 | FileCheck %s
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
3 #include "test.h"
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
4
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
5 long X, Y;
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
6
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
7 void *Thread(void *arg) {
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
8 __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
9 barrier_wait(&barrier);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
10 barrier_wait(&barrier);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
11 Y = 1;
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
12 return &Y;
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
13 }
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
14
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
15 int main() {
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
16 __tsan_flush_memory();
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
17 barrier_init(&barrier, 2);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
18 __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
19 pthread_t t;
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
20 pthread_create(&t, NULL, Thread, NULL);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
21 barrier_wait(&barrier);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
22 __tsan_flush_memory();
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
23 // Trigger a race to test flushing of the symbolizer cache.
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
24 Y = 2;
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
25 barrier_wait(&barrier);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
26 pthread_join(t, NULL);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
27 __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
28 // Background runtime thread should do some flushes meanwhile.
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
29 sleep(2);
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
30 __tsan_flush_memory();
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
31 fprintf(stderr, "DONE\n");
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
32 // The race may not be detected since we are doing aggressive flushes
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
33 // (if the state flush happens between racing accesses, tsan won't
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
34 // detect the race). So return 1 to make the test deterministic.
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
35 return 1;
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
36 }
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
37
c4bab56944e8 LLVM 16
kono
parents:
diff changeset
38 // CHECK: DONE