Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / longjmp4.cpp
blobfd31c9c6144a0ddc902698e83ddbedc2f7479711
1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <setjmp.h>
7 #include <string.h>
9 void bar(jmp_buf env) {
10 volatile int x = 42;
11 jmp_buf env2;
12 memcpy(env2, env, sizeof(jmp_buf));
13 longjmp(env2, 42);
14 x++;
17 void foo(jmp_buf env) {
18 volatile int x = 42;
19 bar(env);
20 x++;
23 __attribute__((noinline)) void badguy() {
24 pthread_mutex_t mtx;
25 pthread_mutex_init(&mtx, 0);
26 pthread_mutex_lock(&mtx);
27 pthread_mutex_destroy(&mtx);
30 __attribute__((noinline)) void mymain() {
31 jmp_buf env;
32 if (setjmp(env) == 42) {
33 badguy();
34 return;
36 foo(env);
37 fprintf(stderr, "FAILED\n");
40 int main() {
41 volatile int x = 42;
42 mymain();
43 return x;
46 // CHECK-NOT: FAILED
47 // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
48 // CHECK: #0 pthread_mutex_destroy
49 // CHECK: #1 badguy
50 // CHECK: #2 mymain
51 // CHECK: #3 main