[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / stream-errno-note.c
blob111841efe0e5a1b9d7f7a570ca103e92facdece5
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=alpha.unix.StdCLibraryFunctions \
5 // RUN: -analyzer-config alpha.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{{Assuming that function 'fopen' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
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{{Assuming that function 'tmpfile' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
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{{Assuming that function 'freopen' is successful}}
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{{Assuming that function 'fclose' is successful}}
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{{Assuming that function 'fread' is successful}}
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_fwrite(void) {
79 char Buf[] = "0123456789";
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 int R = fwrite(Buf, 1, 10, F);
86 // expected-note@-1{{Assuming that function 'fwrite' is successful}}
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'}}
89 (void)fclose(F);
92 void check_fseek(void) {
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 (void)fseek(F, 11, SEEK_SET);
99 // expected-note@-1{{Assuming that function 'fseek' is successful}}
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'}}
102 (void)fclose(F);
105 void check_rewind_errnocheck(void) {
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 errno = 0;
112 rewind(F); // expected-note{{Function 'rewind' indicates failure only by setting of 'errno'}}
113 fclose(F); // expected-warning{{Value of 'errno' was not checked and may be overwritten by function 'fclose' [alpha.unix.Errno]}}
114 // expected-note@-1{{Value of 'errno' was not checked and may be overwritten by function 'fclose'}}
117 void check_fileno(void) {
118 FILE *F = tmpfile();
119 // expected-note@+2{{'F' is non-null}}
120 // expected-note@+1{{Taking false branch}}
121 if (!F)
122 return;
123 fileno(F);
124 // expected-note@-1{{Assuming that function 'fileno' is successful}}
125 if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
126 // expected-note@-1{{An undefined value may be read from 'errno'}}
127 (void)fclose(F);