• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2 // UNSUPPORTED: tvos, watchos
3 // XFAIL: ios && !iossim
4 #include "sanitizer_common/sanitizer_ucontext.h"
5 #include "test.h"
6 
7 char stack[64 * 1024] __attribute__((aligned(16)));
8 
9 ucontext_t uc, orig_uc;
10 void *fiber, *orig_fiber;
11 
12 int var;
13 
func()14 void func() {
15   var = 1;
16   __tsan_switch_to_fiber(orig_fiber, __tsan_switch_to_fiber_no_sync);
17   swapcontext(&uc, &orig_uc);
18 }
19 
main()20 int 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 race
37 // CHECK: PASS
38