[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / stream-stdlibraryfunctionargs.c
bloba14befde5103810e83fa4aa388a4aecf5a5e6053
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctions,debug.ExprInspection \
2 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s
4 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection \
5 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s
7 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.StdCLibraryFunctions,debug.ExprInspection \
8 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stdfunc,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); // \
22 // stream-warning{{Stream pointer might be NULL}} \
23 // stdfunc-warning{{should not be NULL}}
26 void test_tmpfile(void) {
27 FILE *fp = tmpfile();
28 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}} any-warning{{FALSE}}
29 fclose(fp); // \
30 // stream-warning{{Stream pointer might be NULL}} \
31 // stdfunc-warning{{should not be NULL}}
34 void test_fclose(void) {
35 FILE *fp = tmpfile();
36 fclose(fp); // \
37 // stream-warning{{Stream pointer might be NULL}} \
38 // stdfunc-warning{{should not be NULL}}
39 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
42 void test_freopen(void) {
43 FILE *fp = tmpfile();
44 fp = freopen("file", "w", fp); // \
45 // stream-warning{{Stream pointer might be NULL}} \
46 // stdfunc-warning{{should not be NULL}}
47 fclose(fp); // \
48 // stream-warning{{Stream pointer might be NULL}} \
49 // stdfunc-warning{{should not be NULL}}
50 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
53 void test_fread(void) {
54 FILE *fp = tmpfile();
55 size_t ret = fread(buf, size, n, fp); // \
56 // stream-warning{{Stream pointer might be NULL}} \
57 // stdfunc-warning{{The 4th argument to 'fread' is NULL but should not be NULL}}
58 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
59 clang_analyzer_eval(ret <= n); // any-warning{{TRUE}}
60 clang_analyzer_eval(ret == n); // any-warning{{TRUE}} any-warning{{FALSE}}
62 fclose(fp);
65 void test_fwrite(void) {
66 FILE *fp = tmpfile();
67 size_t ret = fwrite(buf, size, n, fp); // \
68 // stream-warning{{Stream pointer might be NULL}} \
69 // stdfunc-warning{{The 4th argument to 'fwrite' is NULL but should not be NULL}}
70 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
71 clang_analyzer_eval(ret <= n); // any-warning{{TRUE}}
72 clang_analyzer_eval(ret == n); // any-warning{{TRUE}} any-warning{{FALSE}}
74 fclose(fp);
77 void test_fseek(void) {
78 FILE *fp = tmpfile();
79 fseek(fp, 0, 0); // \
80 // stream-warning{{Stream pointer might be NULL}} \
81 // stdfunc-warning{{should not be NULL}}
82 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
83 fclose(fp);
86 void test_ftell(void) {
87 FILE *fp = tmpfile();
88 ftell(fp); // \
89 // stream-warning{{Stream pointer might be NULL}} \
90 // stdfunc-warning{{should not be NULL}}
91 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
92 fclose(fp);
95 void test_rewind(void) {
96 FILE *fp = tmpfile();
97 rewind(fp); // \
98 // stream-warning{{Stream pointer might be NULL}} \
99 // stdfunc-warning{{should not be NULL}}
100 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
101 fclose(fp);
104 void test_fgetpos(void) {
105 FILE *fp = tmpfile();
106 fpos_t pos;
107 fgetpos(fp, &pos); // \
108 // stream-warning{{Stream pointer might be NULL}} \
109 // stdfunc-warning{{should not be NULL}}
110 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
111 fclose(fp);
114 void test_fsetpos(void) {
115 FILE *fp = tmpfile();
116 fpos_t pos;
117 fsetpos(fp, &pos); // \
118 // stream-warning{{Stream pointer might be NULL}} \
119 // stdfunc-warning{{should not be NULL}}
120 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
121 fclose(fp);
124 void test_clearerr(void) {
125 FILE *fp = tmpfile();
126 clearerr(fp); // \
127 // stream-warning{{Stream pointer might be NULL}} \
128 // stdfunc-warning{{should not be NULL}}
129 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
130 fclose(fp);
133 void test_feof(void) {
134 FILE *fp = tmpfile();
135 feof(fp); // \
136 // stream-warning{{Stream pointer might be NULL}} \
137 // stdfunc-warning{{should not be NULL}}
138 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
139 fclose(fp);
142 void test_ferror(void) {
143 FILE *fp = tmpfile();
144 ferror(fp); // \
145 // stream-warning{{Stream pointer might be NULL}} \
146 // stdfunc-warning{{should not be NULL}}
147 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
148 fclose(fp);
151 void test_fileno(void) {
152 FILE *fp = tmpfile();
153 fileno(fp); // \
154 // stream-warning{{Stream pointer might be NULL}} \
155 // stdfunc-warning{{should not be NULL}}
156 clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
157 fclose(fp);