[ELF] Avoid make in elf::writeARMCmseImportLib
[llvm-project.git] / clang / test / Analysis / stream-noopen.c
blob87761b3afb76b431d6ba09020db2afd8a98ec695
1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=unix.Errno \
4 // RUN: -analyzer-checker=unix.Stream \
5 // RUN: -analyzer-checker=unix.StdCLibraryFunctions \
6 // RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true \
7 // RUN: -analyzer-checker=debug.ExprInspection
9 // enable only StdCLibraryFunctions checker
10 // RUN: %clang_analyze_cc1 -verify %s \
11 // RUN: -analyzer-checker=core \
12 // RUN: -analyzer-checker=unix.Errno \
13 // RUN: -analyzer-checker=unix.StdCLibraryFunctions \
14 // RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true \
15 // RUN: -analyzer-checker=debug.ExprInspection
17 #include "Inputs/system-header-simulator.h"
18 #include "Inputs/errno_var.h"
20 void clang_analyzer_eval(int);
22 const char *WBuf = "123456789";
23 char RBuf[10];
25 void test_freopen(FILE *F) {
26 F = freopen("xxx", "w", F);
27 if (F) {
28 if (errno) {} // expected-warning{{undefined}}
29 } else {
30 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
34 void test_fread(FILE *F) {
35 size_t Ret = fread(RBuf, 1, 10, F);
36 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
37 if (Ret == 10) {
38 if (errno) {} // expected-warning{{undefined}}
39 } else {
40 clang_analyzer_eval(Ret < 10); // expected-warning {{TRUE}}
41 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
43 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
44 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
47 void test_fwrite(FILE *F) {
48 size_t Ret = fwrite(WBuf, 1, 10, F);
49 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
50 if (Ret == 10) {
51 if (errno) {} // expected-warning{{undefined}}
52 } else {
53 clang_analyzer_eval(Ret < 10); // expected-warning {{TRUE}}
54 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
56 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
57 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
60 void test_fgetc(FILE *F) {
61 int Ret = fgetc(F);
62 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
63 if (Ret != EOF) {
64 if (errno) {} // expected-warning {{undefined}}
65 } else {
66 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
67 // expected-warning@-1 {{FALSE}}
69 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
70 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
73 void test_fputc(FILE *F) {
74 int Ret = fputc('a', F);
75 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
76 if (Ret != EOF) {
77 clang_analyzer_eval(Ret == 'a'); // expected-warning {{TRUE}}
78 if (errno) {} // expected-warning {{undefined}}
79 } else {
80 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
82 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
83 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
86 void test_fgets(char *Buf, int N, FILE *F) {
87 char *Ret = fgets(Buf, N, F);
88 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
89 clang_analyzer_eval(Buf != NULL); // expected-warning {{TRUE}}
90 clang_analyzer_eval(N >= 0); // expected-warning {{TRUE}}
91 if (Ret == Buf) {
92 if (errno) {} // expected-warning {{undefined}}
93 } else {
94 clang_analyzer_eval(Ret == 0); // expected-warning {{TRUE}}
95 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
96 // expected-warning@-1 {{FALSE}}
98 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
99 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
101 char Buf1[10];
102 Ret = fgets(Buf1, 11, F); // expected-warning {{The 1st argument to 'fgets' is a buffer with size 10}}
105 void test_fgets_bufsize(FILE *F) {
106 char Buf[10];
107 fgets(Buf, 11, F); // expected-warning {{The 1st argument to 'fgets' is a buffer with size 10}}
110 void test_fputs(char *Buf, FILE *F) {
111 int Ret = fputs(Buf, F);
112 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
113 clang_analyzer_eval(Buf != NULL); // expected-warning {{TRUE}}
114 if (Ret >= 0) {
115 if (errno) {} // expected-warning {{undefined}}
116 } else {
117 clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
118 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
120 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
121 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
124 void test_ungetc(FILE *F) {
125 int Ret = ungetc('X', F);
126 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
127 if (Ret == 'X') {
128 if (errno) {} // expected-warning {{undefined}}
129 } else {
130 clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
131 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
133 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
134 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
137 void test_ungetc_EOF(FILE *F, int C) {
138 int Ret = ungetc(EOF, F);
139 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
140 clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
141 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
142 Ret = ungetc(C, F);
143 if (Ret == EOF) {
144 clang_analyzer_eval(C == EOF); // expected-warning {{TRUE}}
145 // expected-warning@-1{{FALSE}}
149 void test_fclose(FILE *F) {
150 int Ret = fclose(F);
151 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
152 if (Ret == 0) {
153 if (errno) {} // expected-warning{{undefined}}
154 } else {
155 clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
156 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
158 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
159 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
162 void test_fseek(FILE *F) {
163 int Ret = fseek(F, SEEK_SET, 1);
164 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
165 if (Ret == 0) {
166 if (errno) {} // expected-warning{{undefined}}
167 } else {
168 clang_analyzer_eval(Ret == -1); // expected-warning {{TRUE}}
169 clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
171 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
172 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
175 void check_fgetpos(FILE *F) {
176 errno = 0;
177 fpos_t Pos;
178 int Ret = fgetpos(F, &Pos);
179 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
180 if (Ret)
181 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
182 else
183 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
184 // expected-warning@-1{{FALSE}}
185 if (errno) {} // no-warning
186 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
187 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
190 void check_fsetpos(FILE *F) {
191 errno = 0;
192 fpos_t Pos;
193 int Ret = fsetpos(F, &Pos);
194 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
195 if (Ret)
196 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
197 else
198 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
199 // expected-warning@-1{{FALSE}}
200 if (errno) {} // no-warning
201 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
202 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
205 void check_ftell(FILE *F) {
206 errno = 0;
207 long Ret = ftell(F);
208 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
209 if (Ret == -1) {
210 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
211 } else {
212 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
213 // expected-warning@-1{{FALSE}}
214 clang_analyzer_eval(Ret >= 0); // expected-warning{{TRUE}}
216 if (errno) {} // no-warning
217 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
218 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
221 void test_rewind(FILE *F) {
222 errno = 0;
223 rewind(F);
224 clang_analyzer_eval(F != NULL); // expected-warning{{TRUE}}
225 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
226 // expected-warning@-1{{FALSE}}
227 rewind(F);
230 void test_fflush(FILE *F) {
231 errno = 0;
232 int Ret = fflush(F);
233 clang_analyzer_eval(F != NULL); // expected-warning{{TRUE}}
234 // expected-warning@-1{{FALSE}}
235 if (Ret == EOF) {
236 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
237 } else {
238 clang_analyzer_eval(Ret == 0); // expected-warning{{TRUE}}
239 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
240 // expected-warning@-1{{FALSE}}
244 void test_feof(FILE *F) {
245 errno = 0;
246 feof(F);
247 clang_analyzer_eval(F != NULL); // expected-warning{{TRUE}}
248 if (errno) {} // no-warning
249 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
250 // expected-warning@-1{{FALSE}}
253 void test_ferror(FILE *F) {
254 errno = 0;
255 ferror(F);
256 clang_analyzer_eval(F != NULL); // expected-warning{{TRUE}}
257 if (errno) {} // no-warning
258 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
259 // expected-warning@-1{{FALSE}}
262 void test_clearerr(FILE *F) {
263 errno = 0;
264 clearerr(F);
265 clang_analyzer_eval(F != NULL); // expected-warning{{TRUE}}
266 if (errno) {} // no-warning
267 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
268 // expected-warning@-1{{FALSE}}
271 void test_fileno(FILE *F) {
272 errno = 0;
273 int A = fileno(F);
274 clang_analyzer_eval(F != NULL); // expected-warning{{TRUE}}
275 clang_analyzer_eval(A >= 0); // expected-warning{{TRUE}}
276 if (errno) {} // no-warning
277 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
278 // expected-warning@-1{{FALSE}}
281 void freadwrite_zerosize(FILE *F) {
282 fwrite(WBuf, 1, 0, F);
283 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
284 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
285 fwrite(WBuf, 0, 1, F);
286 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
287 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
288 fread(RBuf, 1, 0, F);
289 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
290 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
291 fread(RBuf, 0, 1, F);
292 clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
293 clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
296 void freadwrite_zerosize_errno(FILE *F, int A) {
297 switch (A) {
298 case 1:
299 fwrite(WBuf, 1, 0, F);
300 if (errno) {} // expected-warning{{undefined}}
301 break;
302 case 2:
303 fwrite(WBuf, 0, 1, F);
304 if (errno) {} // expected-warning{{undefined}}
305 break;
306 case 3:
307 fread(RBuf, 1, 0, F);
308 if (errno) {} // expected-warning{{undefined}}
309 break;
310 case 4:
311 fread(RBuf, 0, 1, F);
312 if (errno) {} // expected-warning{{undefined}}
313 break;