[LLD][COFF] Separate EC and native exports for ARM64X (#123652)
[llvm-project.git] / clang / test / Misc / caret-diags-multiline.cpp
blob6de6aefa53e8464d925964d08aa20e339128183c
1 // RUN: not %clang_cc1 -std=c++11 -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=5 -Wsometimes-uninitialized %s 2>&1 | FileCheck %s --strict-whitespace
3 void line(int);
5 // Check we expand the range as much as possible within the limit.
7 // CHECK: warning: variable 'a' is used uninitialized whenever 'if' condition is true
8 // CHECK-NEXT: {{^}} if (cond) {
9 // CHECK-NEXT: {{^}} ^~~~{{$}}
10 // CHECK-NEXT: note: uninitialized use occurs here
11 // CHECK-NEXT: {{^}} return a;
12 // CHECK-NEXT: {{^}} ^
13 // CHECK-NEXT: note: remove the 'if' if its condition is always false
14 // CHECK-NEXT: {{^}} if (cond) {
15 // CHECK-NEXT: {{^}} ^~~~~~~~~~~{{$}}
16 // CHECK-NEXT: {{^}} line(1);
17 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
18 // CHECK-NEXT: {{^}} } else {
19 // CHECK-NEXT: {{^}} ~~~~~~{{$}}
20 // CHECK-NEXT: note: initialize the variable
21 int f1(int cond) {
22 int a;
23 if (cond) {
24 line(1);
25 } else {
26 a = 3;
28 return a;
31 // CHECK: warning: variable 'a' is used uninitialized whenever 'if' condition is true
32 // CHECK-NEXT: {{^}} if (cond) {
33 // CHECK-NEXT: {{^}} ^~~~{{$}}
34 // CHECK-NEXT: note: uninitialized use occurs here
35 // CHECK-NEXT: {{^}} return a;
36 // CHECK-NEXT: {{^}} ^
37 // CHECK-NEXT: note: remove the 'if' if its condition is always false
38 // CHECK-NEXT: {{^}} if (cond) {
39 // CHECK-NEXT: {{^}} ^~~~~~~~~~~{{$}}
40 // CHECK-NEXT: {{^}} line(1);
41 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
42 // CHECK-NEXT: {{^}} line(2);
43 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
44 // CHECK-NEXT: {{^}} } else {
45 // CHECK-NEXT: {{^}} ~~~~~~{{$}}
46 // CHECK-NEXT: note: initialize the variable
47 int f2(int cond) {
48 int a;
49 if (cond) {
50 line(1);
51 line(2);
52 } else {
53 a = 3;
55 return a;
58 // CHECK: warning: variable 'a' is used uninitialized whenever 'if' condition is true
59 // CHECK-NEXT: {{^}} if (cond) {
60 // CHECK-NEXT: {{^}} ^~~~{{$}}
61 // CHECK-NEXT: note: uninitialized use occurs here
62 // CHECK-NEXT: {{^}} return a;
63 // CHECK-NEXT: {{^}} ^
64 // CHECK-NEXT: note: remove the 'if' if its condition is always false
65 // CHECK-NEXT: {{^}} if (cond) {
66 // CHECK-NEXT: {{^}} ^~~~~~~~~~~{{$}}
67 // CHECK-NEXT: {{^}} line(1);
68 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
69 // CHECK-NEXT: {{^}} line(2);
70 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
71 // CHECK-NEXT: {{^}} line(3);
72 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
73 // CHECK-NEXT: {{^}} } else {
74 // CHECK-NEXT: {{^}} ~~~~~~{{$}}
75 // CHECK-NEXT: note: initialize the variable
76 int f3(int cond) {
77 int a;
78 if (cond) {
79 line(1);
80 line(2);
81 line(3);
82 } else {
83 a = 3;
85 return a;
88 // CHECK: warning: variable 'a' is used uninitialized whenever 'if' condition is true
89 // CHECK-NEXT: {{^}} if (cond) {
90 // CHECK-NEXT: {{^}} ^~~~{{$}}
91 // CHECK-NEXT: note: uninitialized use occurs here
92 // CHECK-NEXT: {{^}} return a;
93 // CHECK-NEXT: {{^}} ^
94 // CHECK-NEXT: note: remove the 'if' if its condition is always false
95 // CHECK-NEXT: {{^}} if (cond) {
96 // CHECK-NEXT: {{^}} ^~~~~~~~~~~{{$}}
97 // CHECK-NEXT: {{^}} line(1);
98 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
99 // CHECK-NEXT: {{^}} line(2);
100 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
101 // CHECK-NEXT: {{^}} line(3);
102 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
103 // CHECK-NEXT: {{^}} line(4);
104 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
105 // CHECK-NEXT: note: initialize the variable
106 int f4(int cond) {
107 int a;
108 if (cond) {
109 line(1);
110 line(2);
111 line(3);
112 line(4);
113 } else {
114 a = 3;
116 return a;
119 // CHECK: warning: variable 'a' is used uninitialized whenever 'if' condition is true
120 // CHECK-NEXT: {{^}} if (cond) {
121 // CHECK-NEXT: {{^}} ^~~~{{$}}
122 // CHECK-NEXT: note: uninitialized use occurs here
123 // CHECK-NEXT: {{^}} return a;
124 // CHECK-NEXT: {{^}} ^
125 // CHECK-NEXT: note: remove the 'if' if its condition is always false
126 // CHECK-NEXT: {{^}} if (cond) {
127 // CHECK-NEXT: {{^}} ^~~~~~~~~~~{{$}}
128 // CHECK-NEXT: {{^}} line(1);
129 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
130 // CHECK-NEXT: {{^}} line(2);
131 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
132 // CHECK-NEXT: {{^}} line(3);
133 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
134 // CHECK-NEXT: {{^}} line(4);
135 // CHECK-NEXT: {{^}} ~~~~~~~~{{$}}
136 // CHECK-NEXT: note: initialize the variable
137 int f5(int cond) {
138 int a;
139 if (cond) {
140 line(1);
141 line(2);
142 line(3);
143 line(4);
144 line(5);
145 } else {
146 a = 3;
148 return a;
152 // Check that we don't include lines with no interesting code if we can't reach
153 // the interesting part within the line limit.
155 // CHECK: error: no matching function for call to 'g
157 // CHECK: note: candidate template ignored: substitution failure
158 // CHECK-NEXT: {{^}}decltype(T()
159 // CHECK-NEXT: {{^}} ~{{$}}
160 // CHECK-NEXT: {{^}} + 1
161 // CHECK-NEXT: {{^}} + 2
162 // CHECK-NEXT: {{^}} + 3
163 // CHECK-NEXT: {{^}}void g();
164 // CHECK-NEXT: {{^}} ^{{$}}
165 template<typename T>
166 decltype(T()
169 + 3)
170 void g();
172 // CHECK: note: candidate template ignored: substitution failure
173 // CHECK-NEXT: {{^}}void g();
174 // CHECK-NEXT: {{^}} ^{{$}}
175 template<typename T>
176 decltype(T()
180 + 4)
181 void g();
183 void h() { g<int()>(); }
186 void multiple_ranges(int a, int b) {
187 // CHECK: error: invalid operands
188 // CHECK-NEXT: &(a)
189 // CHECK-NEXT: ~~~~
190 // CHECK-NEXT: +
191 // CHECK-NEXT: ^
192 // CHECK-NEXT: &(b)
193 // CHECK-NEXT: ~~~~
194 &(a)
196 &(b);
198 // CHECK-NEXT: error: invalid operands
199 // CHECK-NEXT: &(
200 // CHECK-NEXT: ~~
201 // CHECK-NEXT: a
202 // CHECK-NEXT: ~
203 // CHECK-NEXT: )
204 // CHECK-NEXT: ~
205 // CHECK-NEXT: +
206 // CHECK-NEXT: ^
207 // CHECK-NEXT: &(
208 // CHECK-NEXT: ~~
217 // CHECK-NEXT: error: invalid operands
218 // CHECK-NEXT: &(a
219 // CHECK-NEXT: ~~
220 // CHECK-NEXT: )
221 // CHECK-NEXT: ~
222 // CHECK-NEXT: +
223 // CHECK-NEXT: ^
224 // CHECK-NEXT: &(
225 // CHECK-NEXT: ~~
226 // CHECK-NEXT: b
227 // CHECK-NEXT: ~
236 #define pr33902_a(b) #b
237 #define pr33902_c(d) _Pragma(pr33902_a(d))
238 #define pr33902_e(f) pr33902_c(GCC warning #f)
239 pr33902_e() pr33902_e()