[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / stream-stdlibraryfunctionargs.c
blob469d40b456914659f49831e94393d898d5edc70f
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);
14 void *buf;
15 size_t size;
16 size_t n;
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) {
26 FILE *fp = tmpfile();
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) {
33 FILE *fp = tmpfile();
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) {
40 FILE *fp = tmpfile();
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) {
49 FILE *fp = tmpfile();
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}}
56 fclose(fp);
59 void test_fwrite(void) {
60 FILE *fp = tmpfile();
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}}
67 fclose(fp);
70 void test_fseek(void) {
71 FILE *fp = tmpfile();
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}}
75 fclose(fp);
78 void test_ftell(void) {
79 FILE *fp = tmpfile();
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}}
83 fclose(fp);
86 void test_rewind(void) {
87 FILE *fp = tmpfile();
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}}
91 fclose(fp);
94 void test_fgetpos(void) {
95 FILE *fp = tmpfile();
96 fpos_t pos;
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}}
100 fclose(fp);
103 void test_fsetpos(void) {
104 FILE *fp = tmpfile();
105 fpos_t pos;
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}}
109 fclose(fp);
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}}
117 fclose(fp);
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}}
125 fclose(fp);
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}}
133 fclose(fp);
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}}
141 fclose(fp);