@@ -9,6 +9,16 @@ typedef long off_t;
9
9
typedef decltype (sizeof (int )) size_t;
10
10
typedef struct __posix_spawn_file_actions * posix_spawn_file_actions_t ;
11
11
typedef struct __posix_spawnattr * posix_spawnattr_t ;
12
+ # define __CPU_SETSIZE 1024
13
+ # define __NCPUBITS (8 * sizeof (__cpu_mask))
14
+ typedef unsigned long int __cpu_mask;
15
+ typedef struct
16
+ {
17
+ __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
18
+ } cpu_set_t ;
19
+ typedef struct _opaque_pthread_t *__darwin_pthread_t ;
20
+ typedef __darwin_pthread_t pthread_t ;
21
+ typedef struct pthread_attr_t_ *pthread_attr_t ;
12
22
13
23
extern " C" int posix_fadvise (int fd, off_t offset, off_t len, int advice);
14
24
extern " C" int posix_fallocate (int fd, off_t offset, off_t len);
@@ -23,6 +33,12 @@ extern "C" int posix_spawnp(pid_t *pid, const char *file,
23
33
const posix_spawn_file_actions_t *file_actions,
24
34
const posix_spawnattr_t *attrp,
25
35
char *const argv[], char *const envp[]);
36
+ extern " C" int pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
37
+ extern " C" int pthread_attr_setaffinity_np (pthread_attr_t *attr, size_t cpusetsize, const cpu_set_t *cpuset);
38
+ extern " C" int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy);
39
+ extern " C" int pthread_attr_init (pthread_attr_t *attr);
40
+ extern " C" int pthread_yield (void );
41
+
26
42
27
43
void warningLessThanZero () {
28
44
if (posix_fadvise (0 , 0 , 0 , 0 ) < 0 ) {}
@@ -43,11 +59,38 @@ void warningLessThanZero() {
43
59
if (posix_spawnp (NULL , NULL , NULL , NULL , {NULL }, {NULL }) < 0 ) {}
44
60
// CHECK-MESSAGES: :[[@LINE-1]]:60: warning:
45
61
// CHECK-FIXES: posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) > 0
62
+ if (pthread_create (NULL , NULL , NULL , NULL ) < 0 ) {}
63
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: the comparison always evaluates to false because pthread_create always returns non-negative values
64
+ // CHECK-FIXES: pthread_create(NULL, NULL, NULL, NULL) > 0
65
+ if (pthread_attr_setaffinity_np (NULL , 0 , NULL ) < 0 ) {}
66
+ // CHECK-MESSAGES: :[[@LINE-1]]:50: warning:
67
+ // CHECK-FIXES: pthread_attr_setaffinity_np(NULL, 0, NULL) > 0
68
+ if (pthread_attr_setschedpolicy (NULL , 0 ) < 0 ) {}
69
+ // CHECK-MESSAGES: :[[@LINE-1]]:44: warning:
70
+ // CHECK-FIXES: pthread_attr_setschedpolicy(NULL, 0) > 0)
71
+ if (pthread_attr_init (NULL ) < 0 ) {}
72
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning:
73
+ // CHECK-FIXES: pthread_attr_init(NULL) > 0
74
+ if (pthread_yield () < 0 ) {}
75
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning:
76
+ // CHECK-FIXES: pthread_yield() > 0
77
+
46
78
}
47
79
48
80
void warningAlwaysTrue () {
49
81
if (posix_fadvise (0 , 0 , 0 , 0 ) >= 0 ) {}
50
82
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: the comparison always evaluates to true because posix_fadvise always returns non-negative values
83
+ if (pthread_create (NULL , NULL , NULL , NULL ) >= 0 ) {}
84
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: the comparison always evaluates to true because pthread_create always returns non-negative values
85
+ if (pthread_attr_setaffinity_np (NULL , 0 , NULL ) >= 0 ) {}
86
+ // CHECK-MESSAGES: :[[@LINE-1]]:50: warning:
87
+ if (pthread_attr_setschedpolicy (NULL , 0 ) >= 0 ) {}
88
+ // CHECK-MESSAGES: :[[@LINE-1]]:44: warning:
89
+ if (pthread_attr_init (NULL ) >= 0 ) {}
90
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning:
91
+ if (pthread_yield () >= 0 ) {}
92
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning:
93
+
51
94
}
52
95
53
96
void warningEqualsNegative () {
@@ -69,6 +112,15 @@ void warningEqualsNegative() {
69
112
// CHECK-MESSAGES: :[[@LINE-1]]:59: warning:
70
113
if (posix_spawnp (NULL , NULL , NULL , NULL , {NULL }, {NULL }) == -1 ) {}
71
114
// CHECK-MESSAGES: :[[@LINE-1]]:60: warning:
115
+ if (pthread_create (NULL , NULL , NULL , NULL ) == -1 ) {}
116
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: pthread_create
117
+ if (pthread_create (NULL , NULL , NULL , NULL ) != -1 ) {}
118
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
119
+ if (pthread_create (NULL , NULL , NULL , NULL ) <= -1 ) {}
120
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
121
+ if (pthread_create (NULL , NULL , NULL , NULL ) < -1 ) {}
122
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
123
+
72
124
}
73
125
74
126
void WarningWithMacro () {
@@ -85,6 +137,20 @@ void WarningWithMacro() {
85
137
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
86
138
if (posix_fadvise (0 , 0 , 0 , 0 ) < NEGATIVE_ONE) {}
87
139
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
140
+ if (pthread_create (NULL , NULL , NULL , NULL ) < ZERO) {}
141
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
142
+ // CHECK-FIXES: pthread_create(NULL, NULL, NULL, NULL) > ZERO
143
+ if (pthread_create (NULL , NULL , NULL , NULL ) >= ZERO) {}
144
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
145
+ if (pthread_create (NULL , NULL , NULL , NULL ) == NEGATIVE_ONE) {}
146
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
147
+ if (pthread_create (NULL , NULL , NULL , NULL ) != NEGATIVE_ONE) {}
148
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
149
+ if (pthread_create (NULL , NULL , NULL , NULL ) <= NEGATIVE_ONE) {}
150
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
151
+ if (pthread_create (NULL , NULL , NULL , NULL ) < NEGATIVE_ONE) {}
152
+ // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
153
+
88
154
}
89
155
90
156
void noWarning () {
@@ -100,6 +166,7 @@ void noWarning() {
100
166
101
167
namespace i {
102
168
int posix_fadvise (int fd, off_t offset, off_t len, int advice);
169
+ int pthread_yield (void );
103
170
104
171
void noWarning () {
105
172
if (posix_fadvise (0 , 0 , 0 , 0 ) < 0 ) {}
@@ -108,13 +175,20 @@ void noWarning() {
108
175
if (posix_fadvise (0 , 0 , 0 , 0 ) != -1 ) {}
109
176
if (posix_fadvise (0 , 0 , 0 , 0 ) <= -1 ) {}
110
177
if (posix_fadvise (0 , 0 , 0 , 0 ) < -1 ) {}
178
+ if (pthread_yield () < 0 ) {}
179
+ if (pthread_yield () >= 0 ) {}
180
+ if (pthread_yield () == -1 ) {}
181
+ if (pthread_yield () != -1 ) {}
182
+ if (pthread_yield () <= -1 ) {}
183
+ if (pthread_yield () < -1 ) {}
111
184
}
112
185
113
186
} // namespace i
114
187
115
188
class G {
116
189
public:
117
190
int posix_fadvise (int fd, off_t offset, off_t len, int advice);
191
+ int pthread_yield (void );
118
192
119
193
void noWarning () {
120
194
if (posix_fadvise (0 , 0 , 0 , 0 ) < 0 ) {}
@@ -123,5 +197,11 @@ class G {
123
197
if (posix_fadvise (0 , 0 , 0 , 0 ) != -1 ) {}
124
198
if (posix_fadvise (0 , 0 , 0 , 0 ) <= -1 ) {}
125
199
if (posix_fadvise (0 , 0 , 0 , 0 ) < -1 ) {}
200
+ if (pthread_yield () < 0 ) {}
201
+ if (pthread_yield () >= 0 ) {}
202
+ if (pthread_yield () == -1 ) {}
203
+ if (pthread_yield () != -1 ) {}
204
+ if (pthread_yield () <= -1 ) {}
205
+ if (pthread_yield () < -1 ) {}
126
206
}
127
207
};
0 commit comments