[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / longjmp4.cc
blob6b0526ef3a663f7d3a69a74956e1fca5242341eb
1 // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <setjmp.h>
6 #include <string.h>
8 void bar(jmp_buf env) {
9 volatile int x = 42;
10 jmp_buf env2;
11 memcpy(env2, env, sizeof(jmp_buf));
12 longjmp(env2, 42);
13 x++;
16 void foo(jmp_buf env) {
17 volatile int x = 42;
18 bar(env);
19 x++;
22 void badguy() {
23 pthread_mutex_t mtx;
24 pthread_mutex_init(&mtx, 0);
25 pthread_mutex_lock(&mtx);
26 pthread_mutex_destroy(&mtx);
29 void mymain() {
30 jmp_buf env;
31 if (setjmp(env) == 42) {
32 badguy();
33 return;
35 foo(env);
36 printf("FAILED\n");
39 int main() {
40 volatile int x = 42;
41 mymain();
42 return x;
45 // CHECK-NOT: FAILED
46 // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
47 // CHECK: #0 pthread_mutex_destroy
48 // CHECK: #1 badguy
49 // CHECK: #2 mymain
50 // CHECK: #3 main