1*7c3d14c8STreehugger Robot // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s 2*7c3d14c8STreehugger Robot 3*7c3d14c8STreehugger Robot // Longjmp assembly has not been implemented for mips64 yet 4*7c3d14c8STreehugger Robot // XFAIL: mips64 5*7c3d14c8STreehugger Robot 6*7c3d14c8STreehugger Robot #include <pthread.h> 7*7c3d14c8STreehugger Robot #include <stdio.h> 8*7c3d14c8STreehugger Robot #include <stdlib.h> 9*7c3d14c8STreehugger Robot #include <setjmp.h> 10*7c3d14c8STreehugger Robot bar(jmp_buf env)11*7c3d14c8STreehugger Robotvoid bar(jmp_buf env) { 12*7c3d14c8STreehugger Robot volatile int x = 42; 13*7c3d14c8STreehugger Robot longjmp(env, 42); 14*7c3d14c8STreehugger Robot x++; 15*7c3d14c8STreehugger Robot } 16*7c3d14c8STreehugger Robot foo(jmp_buf env)17*7c3d14c8STreehugger Robotvoid foo(jmp_buf env) { 18*7c3d14c8STreehugger Robot volatile int x = 42; 19*7c3d14c8STreehugger Robot bar(env); 20*7c3d14c8STreehugger Robot x++; 21*7c3d14c8STreehugger Robot } 22*7c3d14c8STreehugger Robot badguy()23*7c3d14c8STreehugger Robotvoid badguy() { 24*7c3d14c8STreehugger Robot pthread_mutex_t mtx; 25*7c3d14c8STreehugger Robot pthread_mutex_init(&mtx, 0); 26*7c3d14c8STreehugger Robot pthread_mutex_lock(&mtx); 27*7c3d14c8STreehugger Robot pthread_mutex_destroy(&mtx); 28*7c3d14c8STreehugger Robot } 29*7c3d14c8STreehugger Robot mymain()30*7c3d14c8STreehugger Robotvoid mymain() { 31*7c3d14c8STreehugger Robot jmp_buf env; 32*7c3d14c8STreehugger Robot if (setjmp(env) == 42) { 33*7c3d14c8STreehugger Robot badguy(); 34*7c3d14c8STreehugger Robot return; 35*7c3d14c8STreehugger Robot } 36*7c3d14c8STreehugger Robot foo(env); 37*7c3d14c8STreehugger Robot fprintf(stderr, "FAILED\n"); 38*7c3d14c8STreehugger Robot } 39*7c3d14c8STreehugger Robot main()40*7c3d14c8STreehugger Robotint main() { 41*7c3d14c8STreehugger Robot volatile int x = 42; 42*7c3d14c8STreehugger Robot mymain(); 43*7c3d14c8STreehugger Robot return x; 44*7c3d14c8STreehugger Robot } 45*7c3d14c8STreehugger Robot 46*7c3d14c8STreehugger Robot // CHECK-NOT: FAILED 47*7c3d14c8STreehugger Robot // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex 48*7c3d14c8STreehugger Robot // CHECK: #0 pthread_mutex_destroy 49*7c3d14c8STreehugger Robot // CHECK: #1 badguy 50*7c3d14c8STreehugger Robot // CHECK: #2 mymain 51*7c3d14c8STreehugger Robot // CHECK: #3 main 52*7c3d14c8STreehugger Robot 53