[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / tsan / Darwin / external-dups.cpp
blobca1eb3e7cc4318c3d24e36c71182a729082f034e
1 // RUN: %clangxx_tsan %s -o %t
2 // RUN: %deflake %run %t 2>&1 | FileCheck %s
4 #include <thread>
6 #import "../test.h"
8 void *tag;
10 __attribute__((no_sanitize("thread")))
11 void ExternalWrite(void *addr) {
12 __tsan_external_write(addr, __builtin_return_address(0), tag);
15 int main(int argc, char *argv[]) {
16 barrier_init(&barrier, 2);
17 tag = __tsan_external_register_tag("HelloWorld");
18 fprintf(stderr, "Start.\n");
19 // CHECK: Start.
21 for (int i = 0; i < 4; i++) {
22 void *opaque_object = malloc(16);
23 std::thread t1([opaque_object] {
24 ExternalWrite(opaque_object);
25 barrier_wait(&barrier);
26 });
27 std::thread t2([opaque_object] {
28 barrier_wait(&barrier);
29 ExternalWrite(opaque_object);
30 });
31 // CHECK: WARNING: ThreadSanitizer: race on HelloWorld
32 t1.join();
33 t2.join();
36 fprintf(stderr, "First phase done.\n");
37 // CHECK: First phase done.
39 for (int i = 0; i < 4; i++) {
40 void *opaque_object = malloc(16);
41 std::thread t1([opaque_object] {
42 ExternalWrite(opaque_object);
43 barrier_wait(&barrier);
44 });
45 std::thread t2([opaque_object] {
46 barrier_wait(&barrier);
47 ExternalWrite(opaque_object);
48 });
49 // CHECK: WARNING: ThreadSanitizer: race on HelloWorld
50 t1.join();
51 t2.join();
54 fprintf(stderr, "Second phase done.\n");
55 // CHECK: Second phase done.
58 // CHECK: ThreadSanitizer: reported 2 warnings