Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / stream-errno-note.c
blob32d9d4fd9689dfcdc6e13345893381d579132a41
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core \
2 // RUN: -analyzer-checker=alpha.unix.Stream \
3 // RUN: -analyzer-checker=alpha.unix.Errno \
4 // RUN: -analyzer-checker=unix.StdCLibraryFunctions \
5 // RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true \
6 // RUN: -analyzer-output text -verify %s
8 #include "Inputs/system-header-simulator.h"
9 #include "Inputs/errno_func.h"
11 void check_fopen(void) {
12 FILE *F = fopen("xxx", "r");
13 // expected-note@-1{{'errno' may be undefined after successful call to 'fopen'}}
14 // expected-note@+2{{'F' is non-null}}
15 // expected-note@+1{{Taking false branch}}
16 if (!F)
17 return;
18 if (errno) {} // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
19 // expected-note@-1{{An undefined value may be read from 'errno'}}
20 fclose(F);
23 void check_tmpfile(void) {
24 FILE *F = tmpfile();
25 // expected-note@-1{{'errno' may be undefined after successful call to 'tmpfile'}}
26 // expected-note@+2{{'F' is non-null}}
27 // expected-note@+1{{Taking false branch}}
28 if (!F)
29 return;
30 if (errno) {} // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
31 // expected-note@-1{{An undefined value may be read from 'errno'}}
32 fclose(F);
35 void check_freopen(void) {
36 FILE *F = tmpfile();
37 // expected-note@+2{{'F' is non-null}}
38 // expected-note@+1{{Taking false branch}}
39 if (!F)
40 return;
41 F = freopen("xxx", "w", F);
42 // expected-note@-1{{'errno' may be undefined after successful call to 'freopen'}}
43 // expected-note@+2{{'F' is non-null}}
44 // expected-note@+1{{Taking false branch}}
45 if (!F)
46 return;
47 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
48 // expected-note@-1{{An undefined value may be read from 'errno'}}
49 fclose(F);
52 void check_fclose(void) {
53 FILE *F = tmpfile();
54 // expected-note@+2{{'F' is non-null}}
55 // expected-note@+1{{Taking false branch}}
56 if (!F)
57 return;
58 (void)fclose(F);
59 // expected-note@-1{{'errno' may be undefined after successful call to 'fclose'}}
60 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
61 // expected-note@-1{{An undefined value may be read from 'errno'}}
64 void check_fread(void) {
65 char Buf[10];
66 FILE *F = tmpfile();
67 // expected-note@+2{{'F' is non-null}}
68 // expected-note@+1{{Taking false branch}}
69 if (!F)
70 return;
71 (void)fread(Buf, 1, 10, F);
72 // expected-note@-1{{'errno' may be undefined after successful call to 'fread'}}
73 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
74 // expected-note@-1{{An undefined value may be read from 'errno'}}
75 (void)fclose(F);
78 void check_fread_size0(void) {
79 char Buf[10];
80 FILE *F = tmpfile();
81 // expected-note@+2{{'F' is non-null}}
82 // expected-note@+1{{Taking false branch}}
83 if (!F)
84 return;
85 fread(Buf, 0, 1, F);
86 // expected-note@-1{{'errno' may be undefined after successful call to 'fread'}}
87 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
88 // expected-note@-1{{An undefined value may be read from 'errno'}}
91 void check_fread_nmemb0(void) {
92 char Buf[10];
93 FILE *F = tmpfile();
94 // expected-note@+2{{'F' is non-null}}
95 // expected-note@+1{{Taking false branch}}
96 if (!F)
97 return;
98 fread(Buf, 1, 0, F);
99 // expected-note@-1{{'errno' may be undefined after successful call to 'fread'}}
100 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
101 // expected-note@-1{{An undefined value may be read from 'errno'}}
104 void check_fwrite(void) {
105 char Buf[] = "0123456789";
106 FILE *F = tmpfile();
107 // expected-note@+2{{'F' is non-null}}
108 // expected-note@+1{{Taking false branch}}
109 if (!F)
110 return;
111 int R = fwrite(Buf, 1, 10, F);
112 // expected-note@-1{{'errno' may be undefined after successful call to 'fwrite'}}
113 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
114 // expected-note@-1{{An undefined value may be read from 'errno'}}
115 (void)fclose(F);
118 void check_fseek(void) {
119 FILE *F = tmpfile();
120 // expected-note@+2{{'F' is non-null}}
121 // expected-note@+1{{Taking false branch}}
122 if (!F)
123 return;
124 (void)fseek(F, 11, SEEK_SET);
125 // expected-note@-1{{'errno' may be undefined after successful call to 'fseek'}}
126 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
127 // expected-note@-1{{An undefined value may be read from 'errno'}}
128 (void)fclose(F);
131 void check_rewind_errnocheck(void) {
132 FILE *F = tmpfile();
133 // expected-note@+2{{'F' is non-null}}
134 // expected-note@+1{{Taking false branch}}
135 if (!F)
136 return;
137 errno = 0;
138 rewind(F); // expected-note{{'rewind' indicates failure only by setting 'errno'}}
139 fclose(F); // expected-warning{{Value of 'errno' was not checked and may be overwritten by function 'fclose' [alpha.unix.Errno]}}
140 // expected-note@-1{{Value of 'errno' was not checked and may be overwritten by function 'fclose'}}
143 void check_fileno(void) {
144 FILE *F = tmpfile();
145 // expected-note@+2{{'F' is non-null}}
146 // expected-note@+1{{Taking false branch}}
147 if (!F)
148 return;
149 fileno(F);
150 // expected-note@-1{{'errno' may be undefined after successful call to 'fileno'}}
151 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
152 // expected-note@-1{{An undefined value may be read from 'errno'}}
153 (void)fclose(F);