[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / stream-noopen.c
blobbc1d768987f760b09e7dbd91554fc9b34fe5a8a3
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";
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_fclose(FILE *F) {
61 int Ret = fclose(F);
62 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
63 if (Ret == 0) {
64 if (errno) {} // expected-warning{{undefined}}
65 } else {
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}}
76 if (Ret == 0) {
77 if (errno) {} // expected-warning{{undefined}}
78 } else {
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) {
87 errno = 0;
88 fpos_t Pos;
89 int Ret = fgetpos(F, &Pos);
90 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
91 if (Ret)
92 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
93 else
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) {
102 errno = 0;
103 fpos_t Pos;
104 int Ret = fsetpos(F, &Pos);
105 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
106 if (Ret)
107 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
108 else
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) {
117 errno = 0;
118 long Ret = ftell(F);
119 clang_analyzer_eval(F != NULL); // expected-warning {{TRUE}}
120 if (Ret == -1) {
121 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
122 } else {
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) {
133 errno = 0;
134 rewind(F);
135 clang_analyzer_eval(F != NULL); // expected-warning{{TRUE}}
136 clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
137 // expected-warning@-1{{FALSE}}
138 rewind(F);
141 void test_feof(FILE *F) {
142 errno = 0;
143 feof(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) {
151 errno = 0;
152 ferror(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) {
160 errno = 0;
161 clearerr(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) {
184 switch (A) {
185 case 1:
186 fwrite(WBuf, 1, 0, F);
187 if (errno) {} // expected-warning{{undefined}}
188 break;
189 case 2:
190 fwrite(WBuf, 0, 1, F);
191 if (errno) {} // expected-warning{{undefined}}
192 break;
193 case 3:
194 fread(RBuf, 1, 0, F);
195 if (errno) {} // expected-warning{{undefined}}
196 break;
197 case 4:
198 fread(RBuf, 0, 1, F);
199 if (errno) {} // expected-warning{{undefined}}
200 break;