1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctionArgs,debug.ExprInspection \
2 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify=stdargs,any %s
4 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection \
5 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify=any %s
7 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.StdCLibraryFunctionArgs,debug.ExprInspection \
8 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify=stdargs,any %s
10 #include "Inputs/system-header-simulator.h"
12 extern void clang_analyzer_eval(int);
18 void test_fopen(void) {
19 FILE *fp
= fopen("path", "r");
20 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}} any-warning{{FALSE}}
21 fclose(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
22 // stdargs-note{{The 1st argument should not be NULL}}
25 void test_tmpfile(void) {
27 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}} any-warning{{FALSE}}
28 fclose(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
29 // stdargs-note{{The 1st argument should not be NULL}}
32 void test_fclose(void) {
34 fclose(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
35 // stdargs-note{{The 1st argument should not be NULL}}
36 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
39 void test_freopen(void) {
41 fp
= freopen("file", "w", fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
42 // stdargs-note{{The 3rd argument should not be NULL}}
43 fclose(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
44 // stdargs-note{{The 1st argument should not be NULL}}
45 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
48 void test_fread(void) {
50 size_t ret
= fread(buf
, size
, n
, fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
51 // stdargs-note{{The 4th argument should not be NULL}}
52 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
53 clang_analyzer_eval(ret
<= n
); // any-warning{{TRUE}}
54 clang_analyzer_eval(ret
== n
); // any-warning{{TRUE}} any-warning{{FALSE}}
59 void test_fwrite(void) {
61 size_t ret
= fwrite(buf
, size
, n
, fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
62 // stdargs-note{{The 4th argument should not be NULL}}
63 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
64 clang_analyzer_eval(ret
<= n
); // any-warning{{TRUE}}
65 clang_analyzer_eval(ret
== n
); // any-warning{{TRUE}} any-warning{{FALSE}}
70 void test_fseek(void) {
72 fseek(fp
, 0, 0); // stdargs-warning{{Function argument constraint is not satisfied}} \
73 // stdargs-note{{The 1st argument should not be NULL}}
74 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
78 void test_ftell(void) {
80 ftell(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
81 // stdargs-note{{The 1st argument should not be NULL}}
82 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
86 void test_rewind(void) {
88 rewind(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
89 // stdargs-note{{The 1st argument should not be NULL}}
90 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
94 void test_fgetpos(void) {
97 fgetpos(fp
, &pos
); // stdargs-warning{{Function argument constraint is not satisfied}} \
98 // stdargs-note{{The 1st argument should not be NULL}}
99 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
103 void test_fsetpos(void) {
104 FILE *fp
= tmpfile();
106 fsetpos(fp
, &pos
); // stdargs-warning{{Function argument constraint is not satisfied}} \
107 // stdargs-note{{The 1st argument should not be NULL}}
108 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
112 void test_clearerr(void) {
113 FILE *fp
= tmpfile();
114 clearerr(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
115 // stdargs-note{{The 1st argument should not be NULL}}
116 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
120 void test_feof(void) {
121 FILE *fp
= tmpfile();
122 feof(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
123 // stdargs-note{{The 1st argument should not be NULL}}
124 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
128 void test_ferror(void) {
129 FILE *fp
= tmpfile();
130 ferror(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
131 // stdargs-note{{The 1st argument should not be NULL}}
132 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
136 void test_fileno(void) {
137 FILE *fp
= tmpfile();
138 fileno(fp
); // stdargs-warning{{Function argument constraint is not satisfied}} \
139 // stdargs-note{{The 1st argument should not be NULL}}
140 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}