brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · d27379e Raw
50 lines · cpp
1// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s2// UNSUPPORTED: tvos, watchos3// XFAIL: ios && !iossim4#include "sanitizer_common/sanitizer_ucontext.h"5#include "test.h"6 7char stack[64 * 1024] __attribute__((aligned(16)));8 9ucontext_t uc, orig_uc1, orig_uc2;10void *fiber, *orig_fiber1, *orig_fiber2;11 12int var;13 14void *Thread(void *x) {15  orig_fiber2 = __tsan_get_current_fiber();16  swapcontext(&orig_uc2, &orig_uc1);17  return 0;18}19 20void func() {21  pthread_t t;22  pthread_create(&t, 0, Thread, 0);23  pthread_join(t, 0);24  __tsan_switch_to_fiber(orig_fiber1, 0);25  swapcontext(&uc, &orig_uc1);26}27 28int main() {29  orig_fiber1 = __tsan_get_current_fiber();30  fiber = __tsan_create_fiber(0);31  getcontext(&uc);32  uc.uc_stack.ss_sp = stack;33  uc.uc_stack.ss_size = sizeof(stack);34  uc.uc_link = 0;35  makecontext(&uc, func, 0);36  var = 1;37  __tsan_switch_to_fiber(fiber, 0);38  swapcontext(&orig_uc1, &uc);39  var = 2;40  __tsan_switch_to_fiber(orig_fiber2, 0);41  swapcontext(&orig_uc1, &orig_uc2);42  var = 3;43  __tsan_destroy_fiber(fiber);44  fprintf(stderr, "PASS\n");45  return 0;46}47 48// CHECK-NOT: WARNING: ThreadSanitizer:49// CHECK: PASS50