Home | History | Annotate | Download | only in tsan
      1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
      2 #include <pthread.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <setjmp.h>
      6 
      7 void bar(jmp_buf env) {
      8   volatile int x = 42;
      9   longjmp(env, 42);
     10   x++;
     11 }
     12 
     13 void foo(jmp_buf env) {
     14   volatile int x = 42;
     15   bar(env);
     16   x++;
     17 }
     18 
     19 void badguy() {
     20   pthread_mutex_t mtx;
     21   pthread_mutex_init(&mtx, 0);
     22   pthread_mutex_lock(&mtx);
     23   pthread_mutex_destroy(&mtx);
     24 }
     25 
     26 void mymain() {
     27   jmp_buf env;
     28   if (setjmp(env) == 42) {
     29     badguy();
     30     return;
     31   }
     32   foo(env);
     33   printf("FAILED\n");
     34 }
     35 
     36 int main() {
     37   volatile int x = 42;
     38   mymain();
     39   return x;
     40 }
     41 
     42 // CHECK-NOT: FAILED
     43 // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
     44 // CHECK:   #0 pthread_mutex_destroy
     45 // CHECK:   #1 badguy
     46 // CHECK:   #2 mymain
     47 // CHECK:   #3 main
     48 
     49