mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-25 21:11:25 +00:00

I tricked myself into thinking that deadlock detection is off by default in TSan by looking at the default value of the detect_deadlocks flag and outdated docs. (Created a pull request to update docs.) I even managed to confuse others: https://groups.google.com/forum/#!topic/thread-sanitizer/xYvnAYwtoDk However, the default value is overwritten in code (TSan_flags.cc:InitializeFlags). The TSan/deadlock tests also rely on this This changes aligns the default value of the flag with the actual default behavior. Author: yln (Julian Lettner) Reviewed in: https://reviews.llvm.org/D55846 llvm-svn: 349609
36 lines
1.1 KiB
C
36 lines
1.1 KiB
C
// RUN: %clangxx_tsan %s -o %t
|
|
// RUN: not %run %t 2>&1 | FileCheck %s
|
|
// RUN: %env_tsan_opts=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s
|
|
// RUN: %env_tsan_opts=detect_deadlocks=0 %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
|
|
// RUN: echo "deadlock:main" > %t.supp
|
|
// RUN: %env_tsan_opts=suppressions='%t.supp' %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
|
|
// RUN: echo "deadlock:zzzz" > %t.supp
|
|
// RUN: %env_tsan_opts=suppressions='%t.supp' not %run %t 2>&1 | FileCheck %s
|
|
#include <pthread.h>
|
|
#include <stdio.h>
|
|
|
|
int main() {
|
|
pthread_mutex_t mu1, mu2;
|
|
pthread_mutex_init(&mu1, NULL);
|
|
pthread_mutex_init(&mu2, NULL);
|
|
|
|
// mu1 => mu2
|
|
pthread_mutex_lock(&mu1);
|
|
pthread_mutex_lock(&mu2);
|
|
pthread_mutex_unlock(&mu2);
|
|
pthread_mutex_unlock(&mu1);
|
|
|
|
// mu2 => mu1
|
|
pthread_mutex_lock(&mu2);
|
|
pthread_mutex_lock(&mu1);
|
|
// CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock)
|
|
// DISABLED-NOT: ThreadSanitizer
|
|
// DISABLED: PASS
|
|
pthread_mutex_unlock(&mu1);
|
|
pthread_mutex_unlock(&mu2);
|
|
|
|
pthread_mutex_destroy(&mu1);
|
|
pthread_mutex_destroy(&mu2);
|
|
fprintf(stderr, "PASS\n");
|
|
}
|