1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=alpha.unix.PthreadLock -verify %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc // Tests performing normal locking patterns and wrong locking orders
4f4a2713aSLionel Sambuc
5*0a6a1f1dSLionel Sambuc #include "Inputs/system-header-simulator-for-pthread-lock.h"
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc pthread_mutex_t mtx1, mtx2;
8*0a6a1f1dSLionel Sambuc pthread_mutex_t *pmtx;
9f4a2713aSLionel Sambuc lck_mtx_t lck1, lck2;
10*0a6a1f1dSLionel Sambuc lck_grp_t grp1;
11*0a6a1f1dSLionel Sambuc
12*0a6a1f1dSLionel Sambuc #define NULL 0
13f4a2713aSLionel Sambuc
14f4a2713aSLionel Sambuc void
ok1(void)15f4a2713aSLionel Sambuc ok1(void)
16f4a2713aSLionel Sambuc {
17f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
18f4a2713aSLionel Sambuc }
19f4a2713aSLionel Sambuc
20f4a2713aSLionel Sambuc void
ok2(void)21f4a2713aSLionel Sambuc ok2(void)
22f4a2713aSLionel Sambuc {
23f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
24f4a2713aSLionel Sambuc }
25f4a2713aSLionel Sambuc
26f4a2713aSLionel Sambuc void
ok3(void)27f4a2713aSLionel Sambuc ok3(void)
28f4a2713aSLionel Sambuc {
29f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
30f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
31f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
32f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
33f4a2713aSLionel Sambuc }
34f4a2713aSLionel Sambuc
35f4a2713aSLionel Sambuc void
ok4(void)36f4a2713aSLionel Sambuc ok4(void)
37f4a2713aSLionel Sambuc {
38f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
39f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
40f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx2); // no-warning
41f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx2); // no-warning
42f4a2713aSLionel Sambuc }
43f4a2713aSLionel Sambuc
44f4a2713aSLionel Sambuc void
ok5(void)45f4a2713aSLionel Sambuc ok5(void)
46f4a2713aSLionel Sambuc {
47f4a2713aSLionel Sambuc if (pthread_mutex_trylock(&mtx1) == 0) // no-warning
48f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
49f4a2713aSLionel Sambuc }
50f4a2713aSLionel Sambuc
51f4a2713aSLionel Sambuc void
ok6(void)52f4a2713aSLionel Sambuc ok6(void)
53f4a2713aSLionel Sambuc {
54f4a2713aSLionel Sambuc lck_mtx_lock(&lck1); // no-warning
55f4a2713aSLionel Sambuc }
56f4a2713aSLionel Sambuc
57f4a2713aSLionel Sambuc void
ok7(void)58f4a2713aSLionel Sambuc ok7(void)
59f4a2713aSLionel Sambuc {
60f4a2713aSLionel Sambuc if (lck_mtx_try_lock(&lck1) != 0) // no-warning
61f4a2713aSLionel Sambuc lck_mtx_unlock(&lck1); // no-warning
62f4a2713aSLionel Sambuc }
63f4a2713aSLionel Sambuc
64f4a2713aSLionel Sambuc void
ok8(void)65*0a6a1f1dSLionel Sambuc ok8(void)
66*0a6a1f1dSLionel Sambuc {
67*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
68*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx2); // no-warning
69*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx2); // no-warning
70*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
71*0a6a1f1dSLionel Sambuc }
72*0a6a1f1dSLionel Sambuc
73*0a6a1f1dSLionel Sambuc void
ok9(void)74*0a6a1f1dSLionel Sambuc ok9(void)
75*0a6a1f1dSLionel Sambuc {
76*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
77*0a6a1f1dSLionel Sambuc if (pthread_mutex_trylock(&mtx1) == 0) // no-warning
78*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
79*0a6a1f1dSLionel Sambuc }
80*0a6a1f1dSLionel Sambuc
81*0a6a1f1dSLionel Sambuc void
ok10(void)82*0a6a1f1dSLionel Sambuc ok10(void)
83*0a6a1f1dSLionel Sambuc {
84*0a6a1f1dSLionel Sambuc if (pthread_mutex_trylock(&mtx1) != 0) // no-warning
85*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
86*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
87*0a6a1f1dSLionel Sambuc }
88*0a6a1f1dSLionel Sambuc
89*0a6a1f1dSLionel Sambuc void
ok11(void)90*0a6a1f1dSLionel Sambuc ok11(void)
91*0a6a1f1dSLionel Sambuc {
92*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
93*0a6a1f1dSLionel Sambuc }
94*0a6a1f1dSLionel Sambuc
95*0a6a1f1dSLionel Sambuc void
ok12(void)96*0a6a1f1dSLionel Sambuc ok12(void)
97*0a6a1f1dSLionel Sambuc {
98*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
99*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx2); // no-warning
100*0a6a1f1dSLionel Sambuc }
101*0a6a1f1dSLionel Sambuc
102*0a6a1f1dSLionel Sambuc void
ok13(void)103*0a6a1f1dSLionel Sambuc ok13(void)
104*0a6a1f1dSLionel Sambuc {
105*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
106*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
107*0a6a1f1dSLionel Sambuc }
108*0a6a1f1dSLionel Sambuc
109*0a6a1f1dSLionel Sambuc void
ok14(void)110*0a6a1f1dSLionel Sambuc ok14(void)
111*0a6a1f1dSLionel Sambuc {
112*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
113*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
114*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx2); // no-warning
115*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx2); // no-warning
116*0a6a1f1dSLionel Sambuc }
117*0a6a1f1dSLionel Sambuc
118*0a6a1f1dSLionel Sambuc void
ok15(void)119*0a6a1f1dSLionel Sambuc ok15(void)
120*0a6a1f1dSLionel Sambuc {
121*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
122*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
123*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
124*0a6a1f1dSLionel Sambuc }
125*0a6a1f1dSLionel Sambuc
126*0a6a1f1dSLionel Sambuc void
ok16(void)127*0a6a1f1dSLionel Sambuc ok16(void)
128*0a6a1f1dSLionel Sambuc {
129*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // no-warning
130*0a6a1f1dSLionel Sambuc }
131*0a6a1f1dSLionel Sambuc
132*0a6a1f1dSLionel Sambuc void
ok17(void)133*0a6a1f1dSLionel Sambuc ok17(void)
134*0a6a1f1dSLionel Sambuc {
135*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // no-warning
136*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx2, NULL); // no-warning
137*0a6a1f1dSLionel Sambuc }
138*0a6a1f1dSLionel Sambuc
139*0a6a1f1dSLionel Sambuc void
ok18(void)140*0a6a1f1dSLionel Sambuc ok18(void)
141*0a6a1f1dSLionel Sambuc {
142*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
143*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // no-warning
144*0a6a1f1dSLionel Sambuc }
145*0a6a1f1dSLionel Sambuc
146*0a6a1f1dSLionel Sambuc void
ok19(void)147*0a6a1f1dSLionel Sambuc ok19(void)
148*0a6a1f1dSLionel Sambuc {
149*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
150*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // no-warning
151*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx2); // no-warning
152*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx2, NULL); // no-warning
153*0a6a1f1dSLionel Sambuc }
154*0a6a1f1dSLionel Sambuc
155*0a6a1f1dSLionel Sambuc void
ok20(void)156*0a6a1f1dSLionel Sambuc ok20(void)
157*0a6a1f1dSLionel Sambuc {
158*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
159*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
160*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // no-warning
161*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
162*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // no-warning
163*0a6a1f1dSLionel Sambuc }
164*0a6a1f1dSLionel Sambuc
165*0a6a1f1dSLionel Sambuc void
ok21(void)166*0a6a1f1dSLionel Sambuc ok21(void) {
167*0a6a1f1dSLionel Sambuc pthread_mutex_lock(pmtx); // no-warning
168*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(pmtx); // no-warning
169*0a6a1f1dSLionel Sambuc }
170*0a6a1f1dSLionel Sambuc
171*0a6a1f1dSLionel Sambuc void
ok22(void)172*0a6a1f1dSLionel Sambuc ok22(void) {
173*0a6a1f1dSLionel Sambuc pthread_mutex_lock(pmtx); // no-warning
174*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(pmtx); // no-warning
175*0a6a1f1dSLionel Sambuc pthread_mutex_lock(pmtx); // no-warning
176*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(pmtx); // no-warning
177*0a6a1f1dSLionel Sambuc }
178*0a6a1f1dSLionel Sambuc
179*0a6a1f1dSLionel Sambuc
180*0a6a1f1dSLionel Sambuc void
bad1(void)181f4a2713aSLionel Sambuc bad1(void)
182f4a2713aSLionel Sambuc {
183f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
184f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // expected-warning{{This lock has already been acquired}}
185f4a2713aSLionel Sambuc }
186f4a2713aSLionel Sambuc
187f4a2713aSLionel Sambuc void
bad2(void)188f4a2713aSLionel Sambuc bad2(void)
189f4a2713aSLionel Sambuc {
190f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
191f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
192f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
193f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // expected-warning{{This lock has already been acquired}}
194f4a2713aSLionel Sambuc }
195f4a2713aSLionel Sambuc
196f4a2713aSLionel Sambuc void
bad3(void)197f4a2713aSLionel Sambuc bad3(void)
198f4a2713aSLionel Sambuc {
199f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
200f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx2); // no-warning
201f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx1); // expected-warning{{This was not the most recently acquired lock}}
202f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx2);
203f4a2713aSLionel Sambuc }
204f4a2713aSLionel Sambuc
205f4a2713aSLionel Sambuc void
bad4(void)206f4a2713aSLionel Sambuc bad4(void)
207f4a2713aSLionel Sambuc {
208f4a2713aSLionel Sambuc if (pthread_mutex_trylock(&mtx1)) // no-warning
209f4a2713aSLionel Sambuc return;
210f4a2713aSLionel Sambuc pthread_mutex_lock(&mtx2); // no-warning
211f4a2713aSLionel Sambuc pthread_mutex_unlock(&mtx1); // expected-warning{{This was not the most recently acquired lock}}
212f4a2713aSLionel Sambuc }
213f4a2713aSLionel Sambuc
214f4a2713aSLionel Sambuc void
bad5(void)215f4a2713aSLionel Sambuc bad5(void)
216f4a2713aSLionel Sambuc {
217f4a2713aSLionel Sambuc lck_mtx_lock(&lck1); // no-warning
218f4a2713aSLionel Sambuc lck_mtx_lock(&lck1); // expected-warning{{This lock has already been acquired}}
219f4a2713aSLionel Sambuc }
220f4a2713aSLionel Sambuc
221f4a2713aSLionel Sambuc void
bad6(void)222f4a2713aSLionel Sambuc bad6(void)
223f4a2713aSLionel Sambuc {
224f4a2713aSLionel Sambuc lck_mtx_lock(&lck1); // no-warning
225f4a2713aSLionel Sambuc lck_mtx_unlock(&lck1); // no-warning
226f4a2713aSLionel Sambuc lck_mtx_lock(&lck1); // no-warning
227f4a2713aSLionel Sambuc lck_mtx_lock(&lck1); // expected-warning{{This lock has already been acquired}}
228f4a2713aSLionel Sambuc }
229f4a2713aSLionel Sambuc
230f4a2713aSLionel Sambuc void
bad7(void)231f4a2713aSLionel Sambuc bad7(void)
232f4a2713aSLionel Sambuc {
233f4a2713aSLionel Sambuc lck_mtx_lock(&lck1); // no-warning
234f4a2713aSLionel Sambuc lck_mtx_lock(&lck2); // no-warning
235f4a2713aSLionel Sambuc lck_mtx_unlock(&lck1); // expected-warning{{This was not the most recently acquired lock}}
236f4a2713aSLionel Sambuc lck_mtx_unlock(&lck2);
237f4a2713aSLionel Sambuc }
238f4a2713aSLionel Sambuc
239f4a2713aSLionel Sambuc void
bad8(void)240f4a2713aSLionel Sambuc bad8(void)
241f4a2713aSLionel Sambuc {
242f4a2713aSLionel Sambuc if (lck_mtx_try_lock(&lck1) == 0) // no-warning
243f4a2713aSLionel Sambuc return;
244f4a2713aSLionel Sambuc lck_mtx_lock(&lck2); // no-warning
245f4a2713aSLionel Sambuc lck_mtx_unlock(&lck1); // expected-warning{{This was not the most recently acquired lock}}
246f4a2713aSLionel Sambuc }
247*0a6a1f1dSLionel Sambuc
248*0a6a1f1dSLionel Sambuc void
bad9(void)249*0a6a1f1dSLionel Sambuc bad9(void)
250*0a6a1f1dSLionel Sambuc {
251*0a6a1f1dSLionel Sambuc lck_mtx_unlock(&lck1); // no-warning
252*0a6a1f1dSLionel Sambuc lck_mtx_unlock(&lck1); // expected-warning{{This lock has already been unlocked}}
253*0a6a1f1dSLionel Sambuc }
254*0a6a1f1dSLionel Sambuc
255*0a6a1f1dSLionel Sambuc void
bad10(void)256*0a6a1f1dSLionel Sambuc bad10(void)
257*0a6a1f1dSLionel Sambuc {
258*0a6a1f1dSLionel Sambuc lck_mtx_lock(&lck1); // no-warning
259*0a6a1f1dSLionel Sambuc lck_mtx_unlock(&lck1); // no-warning
260*0a6a1f1dSLionel Sambuc lck_mtx_unlock(&lck1); // expected-warning{{This lock has already been unlocked}}
261*0a6a1f1dSLionel Sambuc }
262*0a6a1f1dSLionel Sambuc
263*0a6a1f1dSLionel Sambuc static void
bad11_sub(pthread_mutex_t * lock)264*0a6a1f1dSLionel Sambuc bad11_sub(pthread_mutex_t *lock)
265*0a6a1f1dSLionel Sambuc {
266*0a6a1f1dSLionel Sambuc lck_mtx_unlock(lock); // expected-warning{{This lock has already been unlocked}}
267*0a6a1f1dSLionel Sambuc }
268*0a6a1f1dSLionel Sambuc
269*0a6a1f1dSLionel Sambuc void
bad11(int i)270*0a6a1f1dSLionel Sambuc bad11(int i)
271*0a6a1f1dSLionel Sambuc {
272*0a6a1f1dSLionel Sambuc lck_mtx_lock(&lck1); // no-warning
273*0a6a1f1dSLionel Sambuc lck_mtx_unlock(&lck1); // no-warning
274*0a6a1f1dSLionel Sambuc if (i < 5)
275*0a6a1f1dSLionel Sambuc bad11_sub(&lck1);
276*0a6a1f1dSLionel Sambuc }
277*0a6a1f1dSLionel Sambuc
278*0a6a1f1dSLionel Sambuc void
bad12(void)279*0a6a1f1dSLionel Sambuc bad12(void)
280*0a6a1f1dSLionel Sambuc {
281*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
282*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
283*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
284*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
285*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // expected-warning{{This lock has already been unlocked}}
286*0a6a1f1dSLionel Sambuc }
287*0a6a1f1dSLionel Sambuc
288*0a6a1f1dSLionel Sambuc void
bad13(void)289*0a6a1f1dSLionel Sambuc bad13(void)
290*0a6a1f1dSLionel Sambuc {
291*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
292*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
293*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx2); // no-warning
294*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx2); // no-warning
295*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // expected-warning{{This lock has already been unlocked}}
296*0a6a1f1dSLionel Sambuc }
297*0a6a1f1dSLionel Sambuc
298*0a6a1f1dSLionel Sambuc void
bad14(void)299*0a6a1f1dSLionel Sambuc bad14(void)
300*0a6a1f1dSLionel Sambuc {
301*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
302*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx2); // no-warning
303*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx2); // no-warning
304*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
305*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx2); // expected-warning{{This lock has already been unlocked}}
306*0a6a1f1dSLionel Sambuc }
307*0a6a1f1dSLionel Sambuc
308*0a6a1f1dSLionel Sambuc void
bad15(void)309*0a6a1f1dSLionel Sambuc bad15(void)
310*0a6a1f1dSLionel Sambuc {
311*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
312*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx2); // no-warning
313*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx2); // no-warning
314*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
315*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
316*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx2); // expected-warning{{This lock has already been unlocked}}
317*0a6a1f1dSLionel Sambuc }
318*0a6a1f1dSLionel Sambuc
319*0a6a1f1dSLionel Sambuc void
bad16(void)320*0a6a1f1dSLionel Sambuc bad16(void)
321*0a6a1f1dSLionel Sambuc {
322*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
323*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // expected-warning{{This lock has already been destroyed}}
324*0a6a1f1dSLionel Sambuc }
325*0a6a1f1dSLionel Sambuc
326*0a6a1f1dSLionel Sambuc void
bad17(void)327*0a6a1f1dSLionel Sambuc bad17(void)
328*0a6a1f1dSLionel Sambuc {
329*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
330*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // expected-warning{{This lock has already been destroyed}}
331*0a6a1f1dSLionel Sambuc }
332*0a6a1f1dSLionel Sambuc
333*0a6a1f1dSLionel Sambuc void
bad18(void)334*0a6a1f1dSLionel Sambuc bad18(void)
335*0a6a1f1dSLionel Sambuc {
336*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // no-warning
337*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // expected-warning{{This lock has already been destroyed}}
338*0a6a1f1dSLionel Sambuc }
339*0a6a1f1dSLionel Sambuc
340*0a6a1f1dSLionel Sambuc void
bad19(void)341*0a6a1f1dSLionel Sambuc bad19(void)
342*0a6a1f1dSLionel Sambuc {
343*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
344*0a6a1f1dSLionel Sambuc pthread_mutex_destroy(&mtx1); // expected-warning{{This lock is still locked}}
345*0a6a1f1dSLionel Sambuc }
346*0a6a1f1dSLionel Sambuc
347*0a6a1f1dSLionel Sambuc void
bad20(void)348*0a6a1f1dSLionel Sambuc bad20(void)
349*0a6a1f1dSLionel Sambuc {
350*0a6a1f1dSLionel Sambuc lck_mtx_destroy(&mtx1, &grp1); // no-warning
351*0a6a1f1dSLionel Sambuc lck_mtx_lock(&mtx1); // expected-warning{{This lock has already been destroyed}}
352*0a6a1f1dSLionel Sambuc }
353*0a6a1f1dSLionel Sambuc
354*0a6a1f1dSLionel Sambuc void
bad21(void)355*0a6a1f1dSLionel Sambuc bad21(void)
356*0a6a1f1dSLionel Sambuc {
357*0a6a1f1dSLionel Sambuc lck_mtx_destroy(&mtx1, &grp1); // no-warning
358*0a6a1f1dSLionel Sambuc lck_mtx_unlock(&mtx1); // expected-warning{{This lock has already been destroyed}}
359*0a6a1f1dSLionel Sambuc }
360*0a6a1f1dSLionel Sambuc
361*0a6a1f1dSLionel Sambuc void
bad22(void)362*0a6a1f1dSLionel Sambuc bad22(void)
363*0a6a1f1dSLionel Sambuc {
364*0a6a1f1dSLionel Sambuc lck_mtx_destroy(&mtx1, &grp1); // no-warning
365*0a6a1f1dSLionel Sambuc lck_mtx_destroy(&mtx1, &grp1); // expected-warning{{This lock has already been destroyed}}
366*0a6a1f1dSLionel Sambuc }
367*0a6a1f1dSLionel Sambuc
368*0a6a1f1dSLionel Sambuc void
bad23(void)369*0a6a1f1dSLionel Sambuc bad23(void)
370*0a6a1f1dSLionel Sambuc {
371*0a6a1f1dSLionel Sambuc lck_mtx_lock(&mtx1); // no-warning
372*0a6a1f1dSLionel Sambuc lck_mtx_destroy(&mtx1, &grp1); // expected-warning{{This lock is still locked}}
373*0a6a1f1dSLionel Sambuc }
374*0a6a1f1dSLionel Sambuc
375*0a6a1f1dSLionel Sambuc void
bad24(void)376*0a6a1f1dSLionel Sambuc bad24(void)
377*0a6a1f1dSLionel Sambuc {
378*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // no-warning
379*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // expected-warning{{This lock has already been initialized}}
380*0a6a1f1dSLionel Sambuc }
381*0a6a1f1dSLionel Sambuc
382*0a6a1f1dSLionel Sambuc void
bad25(void)383*0a6a1f1dSLionel Sambuc bad25(void)
384*0a6a1f1dSLionel Sambuc {
385*0a6a1f1dSLionel Sambuc pthread_mutex_lock(&mtx1); // no-warning
386*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // expected-warning{{This lock is still being held}}
387*0a6a1f1dSLionel Sambuc }
388*0a6a1f1dSLionel Sambuc
389*0a6a1f1dSLionel Sambuc void
bad26(void)390*0a6a1f1dSLionel Sambuc bad26(void)
391*0a6a1f1dSLionel Sambuc {
392*0a6a1f1dSLionel Sambuc pthread_mutex_unlock(&mtx1); // no-warning
393*0a6a1f1dSLionel Sambuc pthread_mutex_init(&mtx1, NULL); // expected-warning{{This lock has already been initialized}}
394*0a6a1f1dSLionel Sambuc }
395