1 | // RUN: %check_clang_tidy %s bugprone-spuriously-wake-up-functions %t -- -- |
2 | #define NULL 0 |
3 | |
4 | struct Node1 { |
5 | void *Node1; |
6 | struct Node1 *next; |
7 | }; |
8 | |
9 | typedef struct mtx_t { |
10 | } mtx_t; |
11 | typedef struct cnd_t { |
12 | } cnd_t; |
13 | struct timespec {}; |
14 | |
15 | int cnd_wait(cnd_t *cond, mtx_t *mutex){}; |
16 | int cnd_timedwait(cnd_t *cond, mtx_t *mutex, |
17 | const struct timespec *time_point){}; |
18 | |
19 | struct Node1 list_c; |
20 | static mtx_t lock; |
21 | static cnd_t condition_c; |
22 | struct timespec ts; |
23 | |
24 | void consume_list_element(void) { |
25 | |
26 | if (list_c.next == NULL) { |
27 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) { |
28 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'cnd_wait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
29 | } |
30 | } |
31 | if (list_c.next == NULL) |
32 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) |
33 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'cnd_wait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
34 | ; |
35 | if (list_c.next == NULL && 0 != cnd_wait(cond: &condition_c, mutex: &lock)) |
36 | // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: 'cnd_wait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
37 | ; |
38 | while (list_c.next == NULL) { |
39 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) { |
40 | } |
41 | } |
42 | while (list_c.next == NULL) |
43 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) { |
44 | } |
45 | while (list_c.next == NULL) |
46 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) |
47 | ; |
48 | if (list_c.next == NULL) { |
49 | cnd_wait(cond: &condition_c, mutex: &lock); |
50 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'cnd_wait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
51 | } |
52 | if (list_c.next == NULL) |
53 | cnd_wait(cond: &condition_c, mutex: &lock); |
54 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'cnd_wait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
55 | while (list_c.next == NULL) { |
56 | cnd_wait(cond: &condition_c, mutex: &lock); |
57 | } |
58 | while (list_c.next == NULL) |
59 | cnd_wait(cond: &condition_c, mutex: &lock); |
60 | |
61 | do { |
62 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) { |
63 | } |
64 | } while (list_c.next == NULL); |
65 | do |
66 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) { |
67 | } |
68 | while (list_c.next == NULL); |
69 | do |
70 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) |
71 | ; |
72 | while (list_c.next == NULL); |
73 | do { |
74 | cnd_wait(cond: &condition_c, mutex: &lock); |
75 | } while (list_c.next == NULL); |
76 | do |
77 | cnd_wait(cond: &condition_c, mutex: &lock); |
78 | while (list_c.next == NULL); |
79 | for (;; list_c.next == NULL) { |
80 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) { |
81 | } |
82 | } |
83 | for (;; list_c.next == NULL) |
84 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) { |
85 | } |
86 | for (;; list_c.next == NULL) |
87 | if (0 != cnd_wait(cond: &condition_c, mutex: &lock)) |
88 | ; |
89 | for (;; list_c.next == NULL) { |
90 | cnd_wait(cond: &condition_c, mutex: &lock); |
91 | } |
92 | for (;; list_c.next == NULL) |
93 | cnd_wait(cond: &condition_c, mutex: &lock); |
94 | |
95 | if (list_c.next == NULL) { |
96 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) { |
97 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'cnd_timedwait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
98 | } |
99 | } |
100 | if (list_c.next == NULL) |
101 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) |
102 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'cnd_timedwait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
103 | ; |
104 | if (list_c.next == NULL && 0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) |
105 | // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: 'cnd_timedwait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
106 | ; |
107 | while (list_c.next == NULL) { |
108 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) { |
109 | } |
110 | } |
111 | while (list_c.next == NULL) |
112 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) { |
113 | } |
114 | while (list_c.next == NULL) |
115 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) |
116 | ; |
117 | if (list_c.next == NULL) { |
118 | cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts); |
119 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'cnd_timedwait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
120 | } |
121 | if (list_c.next == NULL) |
122 | cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts); |
123 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'cnd_timedwait' should be placed inside a while statement [bugprone-spuriously-wake-up-functions] |
124 | while (list_c.next == NULL) { |
125 | cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts); |
126 | } |
127 | while (list_c.next == NULL) |
128 | cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts); |
129 | |
130 | do { |
131 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) { |
132 | } |
133 | } while (list_c.next == NULL); |
134 | do |
135 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) { |
136 | } |
137 | while (list_c.next == NULL); |
138 | do |
139 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) |
140 | ; |
141 | while (list_c.next == NULL); |
142 | do { |
143 | cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts); |
144 | } while (list_c.next == NULL); |
145 | do |
146 | cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts); |
147 | while (list_c.next == NULL); |
148 | for (;; list_c.next == NULL) { |
149 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) { |
150 | } |
151 | } |
152 | for (;; list_c.next == NULL) |
153 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) { |
154 | } |
155 | for (;; list_c.next == NULL) |
156 | if (0 != cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts)) |
157 | ; |
158 | for (;; list_c.next == NULL) { |
159 | cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts); |
160 | } |
161 | for (;; list_c.next == NULL) |
162 | cnd_timedwait(cond: &condition_c, mutex: &lock, time_point: &ts); |
163 | } |
164 | int main(void) { return 0; } |
165 | |