brintos

brintos / llvm-project-archived public Read only

0
0
Text · 904 B · add6694 Raw
38 lines · cpp
1// RUN: %clang_tsan -O1 %s -o %t && %deflake %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_uc;10void *fiber, *orig_fiber;11 12int var;13 14void func() {15  var = 1;16  __tsan_switch_to_fiber(orig_fiber, __tsan_switch_to_fiber_no_sync);17  swapcontext(&uc, &orig_uc);18}19 20int main() {21  orig_fiber = __tsan_get_current_fiber();22  fiber = __tsan_create_fiber(0);23  getcontext(&uc);24  uc.uc_stack.ss_sp = stack;25  uc.uc_stack.ss_size = sizeof(stack);26  uc.uc_link = 0;27  makecontext(&uc, func, 0);28  var = 2;29  __tsan_switch_to_fiber(fiber, __tsan_switch_to_fiber_no_sync);30  swapcontext(&orig_uc, &uc);31  __tsan_destroy_fiber(fiber);32  fprintf(stderr, "PASS\n");33  return 0;34}35 36// CHECK: WARNING: ThreadSanitizer: data race37// CHECK: PASS38