brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 1f10d95 Raw
46 lines · cpp
1// This test verifies that dispatch_sync() doesn't actually copy the block under TSan (without TSan, it doesn't).2 3// RUN: %clangxx_tsan %s -o %t_no_tsan -fno-sanitize=thread4// RUN: %clangxx_tsan %s -o %t_with_tsan5 6// RUN: %run %t_no_tsan   2>&1 | FileCheck %s7// RUN: %run %t_with_tsan 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'8 9#include <dispatch/dispatch.h>10 11#include <stdio.h>12 13struct MyClass {14  static int copyCount;15  static void printCopyCount() {16    fprintf(stderr, "copyCount = %d\n", copyCount);17  }18  MyClass(){};19  MyClass(const MyClass &obj) { copyCount++; };20  void foo() const {21    fprintf(stderr, "MyClass::foo\n");22  }23};24int MyClass::copyCount = 0;25 26int 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();32  };33  MyClass::printCopyCount();34  dispatch_sync(q, block);35  MyClass::printCopyCount();36 37  fprintf(stderr, "Done.\n");38  return 0;39}40 41// CHECK: copyCount = 042// CHECK: copyCount = 143// CHECK: MyClass::foo44// CHECK: copyCount = 145// CHECK: Done.46