Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / fiber_from_thread.cpp
blobd27379e7acf4038a957b4998391f260289f5c56c
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"
7 char stack[64 * 1024] __attribute__((aligned(16)));
9 ucontext_t uc, orig_uc1, orig_uc2;
10 void *fiber, *orig_fiber1, *orig_fiber2;
12 int var;
14 void *Thread(void *x) {
15 orig_fiber2 = __tsan_get_current_fiber();
16 swapcontext(&orig_uc2, &orig_uc1);
17 return 0;
20 void 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);
28 int 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;
48 // CHECK-NOT: WARNING: ThreadSanitizer:
49 // CHECK: PASS