| 1 |
// RUN: %clang_analyze_cc1 \ |
| 2 |
// RUN: -analyzer-checker=unix.BlockInCriticalSection \ |
| 3 |
// RUN: -std=c++11 \ |
| 4 |
// RUN: -analyzer-output text \ |
| 5 |
// RUN: -verify %s |
| 6 |
|
| 7 |
unsigned int sleep(unsigned int seconds) {return 0;} |
| 8 |
namespace std { |
| 9 |
// There are some standard library implementations where some mutex methods |
| 10 |
// come from an implementation detail base class. We need to ensure that these |
| 11 |
// are matched correctly. |
| 12 |
class __mutex_base { |
| 13 |
public: |
| 14 |
void lock(); |
| 15 |
}; |
| 16 |
class mutex : public __mutex_base{ |
| 17 |
public: |
| 18 |
void unlock(); |
| 19 |
bool try_lock(); |
| 20 |
}; |
| 21 |
} // namespace std |
| 22 |
|
| 23 |
void gh_99628() { |
| 24 |
std::mutex m; |
| 25 |
m.lock(); |
| 26 |
// expected-note@-1 {{Entering critical section here}} |
| 27 |
sleep(10); |
| 28 |
// expected-warning@-1 {{Call to blocking function 'sleep' inside of critical section}} |
| 29 |
// expected-note@-2 {{Call to blocking function 'sleep' inside of critical section}} |
| 30 |
m.unlock(); |
| 31 |
} |