Summary: Replace calls to %clang/%clang_cc1 with %clang_analyze_cc1 when invoking static analyzer, and perform runtime substitution to select the appropriate constraint manager, per D28952. Reviewers: xazax.hun, NoQ, zaks.anna, dcoughlin Subscribers: mgorny, rgov, mikhail.ramalho, a.sidorin, cfe-commits Differential Revision: https://reviews.llvm.org/D30373 llvm-svn: 296895
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.unix.BlockInCriticalSection -std=c++11 -verify %s
|
|
|
|
void sleep(int x) {}
|
|
|
|
namespace std {
|
|
struct mutex {
|
|
void lock() {}
|
|
void unlock() {}
|
|
};
|
|
}
|
|
|
|
void testBlockInCriticalSection() {
|
|
std::mutex m;
|
|
m.lock();
|
|
sleep(3); // expected-warning {{A blocking function %s is called inside a critical section}}
|
|
m.unlock();
|
|
}
|
|
|
|
void testBlockInCriticalSectionWithNestedMutexes() {
|
|
std::mutex m, n, k;
|
|
m.lock();
|
|
n.lock();
|
|
k.lock();
|
|
sleep(3); // expected-warning {{A blocking function %s is called inside a critical section}}
|
|
k.unlock();
|
|
sleep(5); // expected-warning {{A blocking function %s is called inside a critical section}}
|
|
n.unlock();
|
|
sleep(3); // expected-warning {{A blocking function %s is called inside a critical section}}
|
|
m.unlock();
|
|
sleep(3); // no-warning
|
|
}
|
|
|
|
void f() {
|
|
sleep(1000); // expected-warning {{A blocking function %s is called inside a critical section}}
|
|
}
|
|
|
|
void testBlockInCriticalSectionInterProcedural() {
|
|
std::mutex m;
|
|
m.lock();
|
|
f();
|
|
m.unlock();
|
|
}
|
|
|
|
void testBlockInCriticalSectionUnexpectedUnlock() {
|
|
std::mutex m;
|
|
m.unlock();
|
|
sleep(1); // no-warning
|
|
m.lock();
|
|
sleep(1); // expected-warning {{A blocking function %s is called inside a critical section}}
|
|
}
|