1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.unix.BlockInCriticalSection -std=c++11 -verify %s
12 lock_guard
<T
>(std::mutex
) {}
17 unique_lock
<T
>(std::mutex
) {}
21 struct not_real_lock
{
22 not_real_lock
<T
>(std::mutex
) {}
31 void pthread_mutex_lock() {}
32 void pthread_mutex_trylock() {}
33 void pthread_mutex_unlock() {}
36 void mtx_timedlock() {}
40 void testBlockInCriticalSectionWithStdMutex() {
43 sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
44 getc(); // expected-warning {{Call to blocking function 'getc' inside of critical section}}
45 fgets(); // expected-warning {{Call to blocking function 'fgets' inside of critical section}}
46 read(); // expected-warning {{Call to blocking function 'read' inside of critical section}}
47 recv(); // expected-warning {{Call to blocking function 'recv' inside of critical section}}
51 void testBlockInCriticalSectionWithPthreadMutex() {
53 sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
54 getc(); // expected-warning {{Call to blocking function 'getc' inside of critical section}}
55 fgets(); // expected-warning {{Call to blocking function 'fgets' inside of critical section}}
56 read(); // expected-warning {{Call to blocking function 'read' inside of critical section}}
57 recv(); // expected-warning {{Call to blocking function 'recv' inside of critical section}}
58 pthread_mutex_unlock();
60 pthread_mutex_trylock();
61 sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
62 getc(); // expected-warning {{Call to blocking function 'getc' inside of critical section}}
63 fgets(); // expected-warning {{Call to blocking function 'fgets' inside of critical section}}
64 read(); // expected-warning {{Call to blocking function 'read' inside of critical section}}
65 recv(); // expected-warning {{Call to blocking function 'recv' inside of critical section}}
66 pthread_mutex_unlock();
69 void testBlockInCriticalSectionC11Locks() {
71 sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
72 getc(); // expected-warning {{Call to blocking function 'getc' inside of critical section}}
73 fgets(); // expected-warning {{Call to blocking function 'fgets' inside of critical section}}
74 read(); // expected-warning {{Call to blocking function 'read' inside of critical section}}
75 recv(); // expected-warning {{Call to blocking function 'recv' inside of critical section}}
79 sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
80 getc(); // expected-warning {{Call to blocking function 'getc' inside of critical section}}
81 fgets(); // expected-warning {{Call to blocking function 'fgets' inside of critical section}}
82 read(); // expected-warning {{Call to blocking function 'read' inside of critical section}}
83 recv(); // expected-warning {{Call to blocking function 'recv' inside of critical section}}
87 sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
88 getc(); // expected-warning {{Call to blocking function 'getc' inside of critical section}}
89 fgets(); // expected-warning {{Call to blocking function 'fgets' inside of critical section}}
90 read(); // expected-warning {{Call to blocking function 'read' inside of critical section}}
91 recv(); // expected-warning {{Call to blocking function 'recv' inside of critical section}}
95 void testBlockInCriticalSectionWithNestedMutexes() {
100 sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
102 sleep(5); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
104 sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
106 sleep(3); // no-warning
110 sleep(1000); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
113 void testBlockInCriticalSectionInterProcedural() {
120 void testBlockInCriticalSectionUnexpectedUnlock() {
123 sleep(1); // no-warning
125 sleep(1); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
128 void testBlockInCriticalSectionLockGuard() {
130 std::not_real_lock
<std::mutex
> not_real_lock(g_mutex
);
131 sleep(1); // no-warning
133 std::lock_guard
<std::mutex
> lock(g_mutex
);
134 sleep(1); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
137 void testBlockInCriticalSectionLockGuardNested() {
138 testBlockInCriticalSectionLockGuard();
139 sleep(1); // no-warning
142 void testBlockInCriticalSectionUniqueLock() {
144 std::not_real_lock
<std::mutex
> not_real_lock(g_mutex
);
145 sleep(1); // no-warning
147 std::unique_lock
<std::mutex
> lock(g_mutex
);
148 sleep(1); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
151 void testBlockInCriticalSectionUniqueLockNested() {
152 testBlockInCriticalSectionUniqueLock();
153 sleep(1); // no-warning