1// RUN: %clang_tsan -O1 %s -o %t && %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
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, 0);
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, 0);
30 swapcontext(&orig_uc, &uc);
31 __tsan_destroy_fiber(fiber);
32 fprintf(stderr, "PASS\n");
33 return 0;
34}
35
36// CHECK-NOT: WARNING: ThreadSanitizer:
37// CHECK: PASS
38