Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / sync-block-copy.cpp
blob1f10d958be280516cf1c88a8abd9f87c51caef7a
1 // This test verifies that dispatch_sync() doesn't actually copy the block under TSan (without TSan, it doesn't).
3 // RUN: %clangxx_tsan %s -o %t_no_tsan -fno-sanitize=thread
4 // RUN: %clangxx_tsan %s -o %t_with_tsan
6 // RUN: %run %t_no_tsan 2>&1 | FileCheck %s
7 // RUN: %run %t_with_tsan 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
9 #include <dispatch/dispatch.h>
11 #include <stdio.h>
13 struct MyClass {
14 static int copyCount;
15 static void printCopyCount() {
16 fprintf(stderr, "copyCount = %d\n", copyCount);
18 MyClass(){};
19 MyClass(const MyClass &obj) { copyCount++; };
20 void foo() const {
21 fprintf(stderr, "MyClass::foo\n");
24 int MyClass::copyCount = 0;
26 int main(int argc, const char* argv[]) {
27 dispatch_queue_t q = dispatch_queue_create("my.queue", NULL);
28 MyClass obj;
29 MyClass::printCopyCount();
30 void (^block)(void) = ^{
31 obj.foo();
33 MyClass::printCopyCount();
34 dispatch_sync(q, block);
35 MyClass::printCopyCount();
37 fprintf(stderr, "Done.\n");
38 return 0;
41 // CHECK: copyCount = 0
42 // CHECK: copyCount = 1
43 // CHECK: MyClass::foo
44 // CHECK: copyCount = 1
45 // CHECK: Done.