1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=alpha.unix.Errno \
4 // RUN: -analyzer-checker=alpha.unix.Stream \
5 // RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
6 // RUN: -analyzer-config apiModeling.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=alpha.unix.Errno \
13 // RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
14 // RUN: -analyzer-config apiModeling.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";
25 void test_freopen(FILE *F
) {
26 F
= freopen("xxx", "w", F
);
28 if (errno
) {} // expected-warning{{undefined}}
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}}
38 if (errno
) {} // expected-warning{{undefined}}
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}}
51 if (errno
) {} // expected-warning{{undefined}}
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_fclose(FILE *F
) {
62 clang_analyzer_eval(F
!= NULL
); // expected-warning {{TRUE}}
64 if (errno
) {} // expected-warning{{undefined}}
66 clang_analyzer_eval(Ret
== EOF
); // expected-warning {{TRUE}}
67 clang_analyzer_eval(errno
!= 0); // expected-warning {{TRUE}}
69 clang_analyzer_eval(feof(F
)); // expected-warning {{UNKNOWN}}
70 clang_analyzer_eval(ferror(F
)); // expected-warning {{UNKNOWN}}
73 void test_fseek(FILE *F
) {
74 int Ret
= fseek(F
, SEEK_SET
, 1);
75 clang_analyzer_eval(F
!= NULL
); // expected-warning {{TRUE}}
77 if (errno
) {} // expected-warning{{undefined}}
79 clang_analyzer_eval(Ret
== -1); // expected-warning {{TRUE}}
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 check_fgetpos(FILE *F
) {
89 int Ret
= fgetpos(F
, &Pos
);
90 clang_analyzer_eval(F
!= NULL
); // expected-warning {{TRUE}}
92 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
94 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
95 // expected-warning@-1{{FALSE}}
96 if (errno
) {} // no-warning
97 clang_analyzer_eval(feof(F
)); // expected-warning {{UNKNOWN}}
98 clang_analyzer_eval(ferror(F
)); // expected-warning {{UNKNOWN}}
101 void check_fsetpos(FILE *F
) {
104 int Ret
= fsetpos(F
, &Pos
);
105 clang_analyzer_eval(F
!= NULL
); // expected-warning {{TRUE}}
107 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
109 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
110 // expected-warning@-1{{FALSE}}
111 if (errno
) {} // no-warning
112 clang_analyzer_eval(feof(F
)); // expected-warning {{UNKNOWN}}
113 clang_analyzer_eval(ferror(F
)); // expected-warning {{UNKNOWN}}
116 void check_ftell(FILE *F
) {
119 clang_analyzer_eval(F
!= NULL
); // expected-warning {{TRUE}}
121 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
123 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
124 // expected-warning@-1{{FALSE}}
125 clang_analyzer_eval(Ret
>= 0); // expected-warning{{TRUE}}
127 if (errno
) {} // no-warning
128 clang_analyzer_eval(feof(F
)); // expected-warning {{UNKNOWN}}
129 clang_analyzer_eval(ferror(F
)); // expected-warning {{UNKNOWN}}
132 void test_rewind(FILE *F
) {
135 clang_analyzer_eval(F
!= NULL
); // expected-warning{{TRUE}}
136 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
137 // expected-warning@-1{{FALSE}}
141 void test_feof(FILE *F
) {
144 clang_analyzer_eval(F
!= NULL
); // expected-warning{{TRUE}}
145 if (errno
) {} // no-warning
146 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
147 // expected-warning@-1{{FALSE}}
150 void test_ferror(FILE *F
) {
153 clang_analyzer_eval(F
!= NULL
); // expected-warning{{TRUE}}
154 if (errno
) {} // no-warning
155 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
156 // expected-warning@-1{{FALSE}}
159 void test_clearerr(FILE *F
) {
162 clang_analyzer_eval(F
!= NULL
); // expected-warning{{TRUE}}
163 if (errno
) {} // no-warning
164 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
165 // expected-warning@-1{{FALSE}}
168 void freadwrite_zerosize(FILE *F
) {
169 fwrite(WBuf
, 1, 0, F
);
170 clang_analyzer_eval(feof(F
)); // expected-warning {{UNKNOWN}}
171 clang_analyzer_eval(ferror(F
)); // expected-warning {{UNKNOWN}}
172 fwrite(WBuf
, 0, 1, F
);
173 clang_analyzer_eval(feof(F
)); // expected-warning {{UNKNOWN}}
174 clang_analyzer_eval(ferror(F
)); // expected-warning {{UNKNOWN}}
175 fread(RBuf
, 1, 0, F
);
176 clang_analyzer_eval(feof(F
)); // expected-warning {{UNKNOWN}}
177 clang_analyzer_eval(ferror(F
)); // expected-warning {{UNKNOWN}}
178 fread(RBuf
, 0, 1, F
);
179 clang_analyzer_eval(feof(F
)); // expected-warning {{UNKNOWN}}
180 clang_analyzer_eval(ferror(F
)); // expected-warning {{UNKNOWN}}
183 void freadwrite_zerosize_errno(FILE *F
, int A
) {
186 fwrite(WBuf
, 1, 0, F
);
187 if (errno
) {} // expected-warning{{undefined}}
190 fwrite(WBuf
, 0, 1, F
);
191 if (errno
) {} // expected-warning{{undefined}}
194 fread(RBuf
, 1, 0, F
);
195 if (errno
) {} // expected-warning{{undefined}}
198 fread(RBuf
, 0, 1, F
);
199 if (errno
) {} // expected-warning{{undefined}}