1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.fuchsia.Lock -verify %s
3 typedef int spin_lock_t
;
4 typedef int zx_status_t
;
7 void spin_lock(spin_lock_t
*lock
);
8 int spin_trylock(spin_lock_t
*lock
);
9 void spin_unlock(spin_lock_t
*lock
);
10 void spin_lock_init(spin_lock_t
*lock
);
12 void spin_lock_save(spin_lock_t
*lock
, void *statep
,
14 void spin_unlock_restore(spin_lock_t
*lock
, void *old_state
,
22 spin_lock(&mtx1
); // no-warning
23 spin_lock(&mtx1
); // expected-warning{{This lock has already been acquired}}
29 spin_unlock(&mtx1
); // expected-warning {{This lock has already been unlocked}}
33 spin_lock_init(&mtx1
);
34 if (spin_trylock(&mtx1
) != 0)
35 spin_unlock(&mtx1
); // expected-warning {{This lock has already been unlocked}}
41 spin_unlock(&mtx1
); // expected-warning {{This was not the most recently acquired lock. Possible lock order reversal}}
48 spin_lock_save(&mtx
, 0, 0);
49 spin_unlock_restore(&mtx
, 0, 0);
55 if (spin_trylock(&mtx
) == 0)
59 typedef int sync_mutex_t
;
60 void sync_mutex_lock(sync_mutex_t
* mutex
);
61 void sync_mutex_lock_with_waiter(sync_mutex_t
* mutex
);
62 zx_status_t
sync_mutex_timedlock(sync_mutex_t
* mutex
, zx_time_t deadline
);
63 zx_status_t
sync_mutex_trylock(sync_mutex_t
* mutex
);
64 void sync_mutex_unlock(sync_mutex_t
* mutex
);
71 sync_mutex_lock(&smtx1
); // no-warning
72 sync_mutex_lock(&smtx1
); // expected-warning{{This lock has already been acquired}}
76 sync_mutex_lock_with_waiter(&smtx1
);
77 sync_mutex_unlock(&smtx1
);
78 sync_mutex_unlock(&smtx1
); // expected-warning {{This lock has already been unlocked}}
82 sync_mutex_unlock(&smtx1
);
83 if (sync_mutex_trylock(&smtx1
) != 0)
84 sync_mutex_unlock(&smtx1
); // expected-warning {{This lock has already been unlocked}}
88 sync_mutex_lock(&smtx1
);
89 sync_mutex_lock(&smtx2
);
90 sync_mutex_unlock(&smtx1
); // expected-warning {{This was not the most recently acquired lock. Possible lock order reversal}}
91 sync_mutex_unlock(&smtx2
);
96 if (sync_mutex_trylock(&mtx
) == 0)
97 sync_mutex_unlock(&mtx
);
102 if (sync_mutex_timedlock(&mtx
, 0) == 0)
103 sync_mutex_unlock(&mtx
);