1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.Errno,apiModeling.StdCLibraryFunctions,debug.ExprInspection \
2 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify %s
4 #include "Inputs/system-header-simulator.h"
5 #include "Inputs/errno_func.h"
7 extern void clang_analyzer_eval(int);
8 extern void clang_analyzer_dump(int);
9 extern void clang_analyzer_printState();
11 void check_fopen(void) {
12 FILE *F
= fopen("xxx", "r");
14 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
15 if (errno
) {} // no-warning
18 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
21 void check_tmpfile(void) {
24 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
25 if (errno
) {} // no-warning
28 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
31 void check_freopen(void) {
35 F
= freopen("xxx", "w", F
);
37 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
38 if (errno
) {} // no-warning
41 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
44 void check_fclose(void) {
50 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
51 if (errno
) {} // no-warning
54 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
57 void check_fread_size0(void) {
63 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
66 void check_fread_nmemb0(void) {
72 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
75 void check_fread(void) {
81 int R
= fread(Buf
, 1, 10, F
);
83 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
84 if (errno
) {} // no-warning
88 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
91 void check_fwrite_size0(void) {
92 char Buf
[] = "0123456789";
97 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
100 void check_fwrite_nmemb0(void) {
101 char Buf
[] = "0123456789";
105 fwrite(Buf
, 1, 0, F
);
106 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
109 void check_fwrite(void) {
110 char Buf
[] = "0123456789";
115 int R
= fwrite(Buf
, 1, 10, F
);
117 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
118 if (errno
) {} // no-warning
122 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
125 void check_fseek(void) {
129 int S
= fseek(F
, 11, SEEK_SET
);
131 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
132 if (errno
) {} // no-warning
136 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
139 void check_no_errno_change(void) {
145 if (errno
) {} // no-warning
147 if (errno
) {} // no-warning
149 if (errno
) {} // no-warning
150 clang_analyzer_eval(errno
== 1); // expected-warning{{TRUE}}
154 void check_fgetpos(void) {
160 int Ret
= fgetpos(F
, &Pos
);
162 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
164 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
165 if (errno
) {} // no-warning
169 void check_fsetpos(void) {
175 int Ret
= fsetpos(F
, &Pos
);
177 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
179 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
180 if (errno
) {} // no-warning
184 void check_ftell(void) {
191 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
193 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
194 clang_analyzer_eval(Ret
>= 0); // expected-warning{{TRUE}}
196 if (errno
) {} // no-warning
200 void check_rewind(void) {
206 clang_analyzer_eval(errno
== 0);
207 // expected-warning@-1{{FALSE}}
208 // expected-warning@-2{{TRUE}}
212 void check_fileno(void) {
218 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
219 if (errno
) {} // no-warning
223 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}