Home | History | Annotate | Download | only in tsan
      1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
      2 
      3 // Longjmp assembly has not been implemented for mips64 yet
      4 // XFAIL: mips64
      5 
      6 #include <pthread.h>
      7 #include <stdio.h>
      8 #include <stdlib.h>
      9 #include <setjmp.h>
     10 
     11 void bar(jmp_buf env) {
     12   volatile int x = 42;
     13   longjmp(env, 42);
     14   x++;
     15 }
     16 
     17 void foo(jmp_buf env) {
     18   volatile int x = 42;
     19   bar(env);
     20   x++;
     21 }
     22 
     23 void badguy() {
     24   pthread_mutex_t mtx;
     25   pthread_mutex_init(&mtx, 0);
     26   pthread_mutex_lock(&mtx);
     27   pthread_mutex_destroy(&mtx);
     28 }
     29 
     30 void mymain() {
     31   jmp_buf env;
     32   if (setjmp(env) == 42) {
     33     badguy();
     34     return;
     35   }
     36   foo(env);
     37   printf("FAILED\n");
     38 }
     39 
     40 int main() {
     41   volatile int x = 42;
     42   mymain();
     43   return x;
     44 }
     45 
     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
     52 
     53