xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/warn-unreachable.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wunreachable-code-aggressive -Wno-unused-value -Wno-covered-switch-default -I %S/Inputs
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc #include "warn-unreachable.h"
4f4a2713aSLionel Sambuc 
5f4a2713aSLionel Sambuc int halt() __attribute__((noreturn));
6f4a2713aSLionel Sambuc int live();
7f4a2713aSLionel Sambuc int dead();
8f4a2713aSLionel Sambuc 
test1()9f4a2713aSLionel Sambuc void test1() {
10f4a2713aSLionel Sambuc   goto c;
11f4a2713aSLionel Sambuc   d:
12f4a2713aSLionel Sambuc   goto e;       // expected-warning {{will never be executed}}
13f4a2713aSLionel Sambuc   c: ;
14f4a2713aSLionel Sambuc   int i;
15f4a2713aSLionel Sambuc   return;
16f4a2713aSLionel Sambuc   goto b;        // expected-warning {{will never be executed}}
17f4a2713aSLionel Sambuc   goto a;        // expected-warning {{will never be executed}}
18f4a2713aSLionel Sambuc   b:
19f4a2713aSLionel Sambuc   i = 1;
20f4a2713aSLionel Sambuc   a:
21f4a2713aSLionel Sambuc   i = 2;
22f4a2713aSLionel Sambuc   goto f;
23f4a2713aSLionel Sambuc   e:
24f4a2713aSLionel Sambuc   goto d;
25f4a2713aSLionel Sambuc   f: ;
26f4a2713aSLionel Sambuc }
27f4a2713aSLionel Sambuc 
test2()28f4a2713aSLionel Sambuc void test2() {
29f4a2713aSLionel Sambuc   int i;
30f4a2713aSLionel Sambuc   switch (live()) {
31f4a2713aSLionel Sambuc   case 1:
32f4a2713aSLionel Sambuc     halt(),
33f4a2713aSLionel Sambuc       dead();   // expected-warning {{will never be executed}}
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc   case 2:
36f4a2713aSLionel Sambuc     live(), halt(),
37f4a2713aSLionel Sambuc       dead();   // expected-warning {{will never be executed}}
38f4a2713aSLionel Sambuc 
39f4a2713aSLionel Sambuc   case 3:
40f4a2713aSLionel Sambuc   live()
41f4a2713aSLionel Sambuc     +           // expected-warning {{will never be executed}}
42f4a2713aSLionel Sambuc     halt();
43f4a2713aSLionel Sambuc   dead();
44f4a2713aSLionel Sambuc 
45f4a2713aSLionel Sambuc   case 4:
46f4a2713aSLionel Sambuc   a4:
47f4a2713aSLionel Sambuc     live(),
48f4a2713aSLionel Sambuc       halt();
49f4a2713aSLionel Sambuc     goto a4;    // expected-warning {{will never be executed}}
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc   case 5:
52f4a2713aSLionel Sambuc     goto a5;
53f4a2713aSLionel Sambuc   c5:
54f4a2713aSLionel Sambuc     dead();     // expected-warning {{will never be executed}}
55f4a2713aSLionel Sambuc     goto b5;
56f4a2713aSLionel Sambuc   a5:
57f4a2713aSLionel Sambuc     live(),
58f4a2713aSLionel Sambuc       halt();
59f4a2713aSLionel Sambuc   b5:
60f4a2713aSLionel Sambuc     goto c5;
61f4a2713aSLionel Sambuc 
62f4a2713aSLionel Sambuc   case 6:
63f4a2713aSLionel Sambuc     if (live())
64f4a2713aSLionel Sambuc       goto e6;
65f4a2713aSLionel Sambuc     live(),
66f4a2713aSLionel Sambuc       halt();
67f4a2713aSLionel Sambuc   d6:
68f4a2713aSLionel Sambuc     dead();     // expected-warning {{will never be executed}}
69f4a2713aSLionel Sambuc     goto b6;
70f4a2713aSLionel Sambuc   c6:
71f4a2713aSLionel Sambuc     dead();
72f4a2713aSLionel Sambuc     goto b6;
73f4a2713aSLionel Sambuc   e6:
74f4a2713aSLionel Sambuc     live(),
75f4a2713aSLionel Sambuc       halt();
76f4a2713aSLionel Sambuc   b6:
77f4a2713aSLionel Sambuc     goto c6;
78f4a2713aSLionel Sambuc   case 7:
79f4a2713aSLionel Sambuc     halt()
80f4a2713aSLionel Sambuc       +
81f4a2713aSLionel Sambuc       dead();   // expected-warning {{will never be executed}}
82f4a2713aSLionel Sambuc     -           // expected-warning {{will never be executed}}
83f4a2713aSLionel Sambuc       halt();
84f4a2713aSLionel Sambuc   case 8:
85f4a2713aSLionel Sambuc     i
86f4a2713aSLionel Sambuc       +=        // expected-warning {{will never be executed}}
87f4a2713aSLionel Sambuc       halt();
88f4a2713aSLionel Sambuc   case 9:
89f4a2713aSLionel Sambuc     halt()
90f4a2713aSLionel Sambuc       ?         // expected-warning {{will never be executed}}
91f4a2713aSLionel Sambuc       dead() : dead();
92f4a2713aSLionel Sambuc   case 10:
93f4a2713aSLionel Sambuc     (           // expected-warning {{will never be executed}}
94f4a2713aSLionel Sambuc       float)halt();
95f4a2713aSLionel Sambuc   case 11: {
96f4a2713aSLionel Sambuc     int a[5];
97f4a2713aSLionel Sambuc     live(),
98f4a2713aSLionel Sambuc       a[halt()
99f4a2713aSLionel Sambuc         ];      // expected-warning {{will never be executed}}
100f4a2713aSLionel Sambuc   }
101f4a2713aSLionel Sambuc   }
102f4a2713aSLionel Sambuc }
103f4a2713aSLionel Sambuc 
104f4a2713aSLionel Sambuc enum Cases { C1, C2, C3 };
test_enum_cases(enum Cases C)105f4a2713aSLionel Sambuc int test_enum_cases(enum Cases C) {
106f4a2713aSLionel Sambuc   switch (C) {
107f4a2713aSLionel Sambuc     case C1:
108f4a2713aSLionel Sambuc     case C2:
109f4a2713aSLionel Sambuc     case C3:
110f4a2713aSLionel Sambuc       return 1;
111f4a2713aSLionel Sambuc     default: {
112*0a6a1f1dSLionel Sambuc       int i = 0; // no-warning
113f4a2713aSLionel Sambuc       ++i;
114f4a2713aSLionel Sambuc       return i;
115f4a2713aSLionel Sambuc     }
116f4a2713aSLionel Sambuc   }
117f4a2713aSLionel Sambuc }
118f4a2713aSLionel Sambuc 
119f4a2713aSLionel Sambuc // Handle unreachable code triggered by macro expansions.
120f4a2713aSLionel Sambuc void __myassert_rtn(const char *, const char *, int, const char *) __attribute__((__noreturn__));
121f4a2713aSLionel Sambuc 
122f4a2713aSLionel Sambuc #define myassert(e) \
123f4a2713aSLionel Sambuc     (__builtin_expect(!(e), 0) ? __myassert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
124f4a2713aSLionel Sambuc 
test_assert()125f4a2713aSLionel Sambuc void test_assert() {
126f4a2713aSLionel Sambuc   myassert(0 && "unreachable");
127f4a2713aSLionel Sambuc   return; // no-warning
128f4a2713aSLionel Sambuc }
129f4a2713aSLionel Sambuc 
130f4a2713aSLionel Sambuc // Test case for PR 9774.  Tests that dead code in macros aren't warned about.
131f4a2713aSLionel Sambuc #define MY_MAX(a,b)     ((a) >= (b) ? (a) : (b))
PR9774(int * s)132f4a2713aSLionel Sambuc void PR9774(int *s) {
133f4a2713aSLionel Sambuc     for (int i = 0; i < MY_MAX(2, 3); i++) // no-warning
134f4a2713aSLionel Sambuc         s[i] = 0;
135f4a2713aSLionel Sambuc }
136f4a2713aSLionel Sambuc 
137f4a2713aSLionel Sambuc // Test case for <rdar://problem/11005770>.  We should treat code guarded
138f4a2713aSLionel Sambuc // by 'x & 0' and 'x * 0' as unreachable.
139*0a6a1f1dSLionel Sambuc int calledFun();
test_mul_and_zero(int x)140f4a2713aSLionel Sambuc void test_mul_and_zero(int x) {
141f4a2713aSLionel Sambuc   if (x & 0) calledFun(); // expected-warning {{will never be executed}}
142f4a2713aSLionel Sambuc   if (0 & x) calledFun(); // expected-warning {{will never be executed}}
143f4a2713aSLionel Sambuc   if (x * 0) calledFun(); // expected-warning {{will never be executed}}
144f4a2713aSLionel Sambuc   if (0 * x) calledFun(); // expected-warning {{will never be executed}}
145f4a2713aSLionel Sambuc }
146*0a6a1f1dSLionel Sambuc 
147*0a6a1f1dSLionel Sambuc void raze() __attribute__((noreturn));
148*0a6a1f1dSLionel Sambuc void warn_here();
149*0a6a1f1dSLionel Sambuc 
test_break_preceded_by_noreturn(int i)150*0a6a1f1dSLionel Sambuc int test_break_preceded_by_noreturn(int i) {
151*0a6a1f1dSLionel Sambuc   switch (i) {
152*0a6a1f1dSLionel Sambuc     case 1:
153*0a6a1f1dSLionel Sambuc       raze();
154*0a6a1f1dSLionel Sambuc       break; // expected-warning {{'break' will never be executed}}
155*0a6a1f1dSLionel Sambuc     case 2:
156*0a6a1f1dSLionel Sambuc       raze();
157*0a6a1f1dSLionel Sambuc       break; // expected-warning {{'break' will never be executed}}
158*0a6a1f1dSLionel Sambuc       warn_here(); // expected-warning {{will never be executed}}
159*0a6a1f1dSLionel Sambuc     case 3:
160*0a6a1f1dSLionel Sambuc       return 1;
161*0a6a1f1dSLionel Sambuc       break; // expected-warning {{will never be executed}}
162*0a6a1f1dSLionel Sambuc     default:
163*0a6a1f1dSLionel Sambuc       break;
164*0a6a1f1dSLionel Sambuc       break; // expected-warning {{will never be executed}}
165*0a6a1f1dSLionel Sambuc   }
166*0a6a1f1dSLionel Sambuc   return i;
167*0a6a1f1dSLionel Sambuc }
168*0a6a1f1dSLionel Sambuc 
169*0a6a1f1dSLionel Sambuc // Don't warn about unreachable 'default' cases, as that is covered
170*0a6a1f1dSLionel Sambuc // by -Wcovered-switch-default.
171*0a6a1f1dSLionel Sambuc typedef enum { Value1 = 1 } MyEnum;
unreachable_default(MyEnum e)172*0a6a1f1dSLionel Sambuc void unreachable_default(MyEnum e) {
173*0a6a1f1dSLionel Sambuc   switch (e) {
174*0a6a1f1dSLionel Sambuc   case Value1:
175*0a6a1f1dSLionel Sambuc     calledFun();
176*0a6a1f1dSLionel Sambuc     break;
177*0a6a1f1dSLionel Sambuc   case 2: // expected-warning {{case value not in enumerated type 'MyEnum'}}
178*0a6a1f1dSLionel Sambuc     calledFun();
179*0a6a1f1dSLionel Sambuc     break;
180*0a6a1f1dSLionel Sambuc   default:
181*0a6a1f1dSLionel Sambuc     calledFun(); // no-warning
182*0a6a1f1dSLionel Sambuc     break;
183*0a6a1f1dSLionel Sambuc   }
184*0a6a1f1dSLionel Sambuc }
unreachable_in_default(MyEnum e)185*0a6a1f1dSLionel Sambuc void unreachable_in_default(MyEnum e) {
186*0a6a1f1dSLionel Sambuc   switch (e) {
187*0a6a1f1dSLionel Sambuc   default:
188*0a6a1f1dSLionel Sambuc     raze();
189*0a6a1f1dSLionel Sambuc     calledFun(); // expected-warning {{will never be executed}}
190*0a6a1f1dSLionel Sambuc     break;
191*0a6a1f1dSLionel Sambuc   }
192*0a6a1f1dSLionel Sambuc }
193*0a6a1f1dSLionel Sambuc 
194*0a6a1f1dSLionel Sambuc // Don't warn about trivial dead returns.
trivial_dead_return()195*0a6a1f1dSLionel Sambuc int trivial_dead_return() {
196*0a6a1f1dSLionel Sambuc   raze();
197*0a6a1f1dSLionel Sambuc   return ((0)); // expected-warning {{'return' will never be executed}}
198*0a6a1f1dSLionel Sambuc }
199*0a6a1f1dSLionel Sambuc 
trivial_dead_return_void()200*0a6a1f1dSLionel Sambuc void trivial_dead_return_void() {
201*0a6a1f1dSLionel Sambuc   raze();
202*0a6a1f1dSLionel Sambuc   return; // expected-warning {{'return' will never be executed}}
203*0a6a1f1dSLionel Sambuc }
204*0a6a1f1dSLionel Sambuc 
trivial_dead_return_enum()205*0a6a1f1dSLionel Sambuc MyEnum trivial_dead_return_enum() {
206*0a6a1f1dSLionel Sambuc   raze();
207*0a6a1f1dSLionel Sambuc   return Value1; // expected-warning {{'return' will never be executed}}
208*0a6a1f1dSLionel Sambuc }
209*0a6a1f1dSLionel Sambuc 
trivial_dead_return_enum_2(int x)210*0a6a1f1dSLionel Sambuc MyEnum trivial_dead_return_enum_2(int x) {
211*0a6a1f1dSLionel Sambuc   switch (x) {
212*0a6a1f1dSLionel Sambuc     case 1: return 1;
213*0a6a1f1dSLionel Sambuc     case 2: return 2;
214*0a6a1f1dSLionel Sambuc     case 3: return 3;
215*0a6a1f1dSLionel Sambuc     default: return 4;
216*0a6a1f1dSLionel Sambuc   }
217*0a6a1f1dSLionel Sambuc 
218*0a6a1f1dSLionel Sambuc   return 2; // expected-warning {{will never be executed}}
219*0a6a1f1dSLionel Sambuc }
220*0a6a1f1dSLionel Sambuc 
trivial_dead_return_cstr()221*0a6a1f1dSLionel Sambuc const char *trivial_dead_return_cstr() {
222*0a6a1f1dSLionel Sambuc   raze();
223*0a6a1f1dSLionel Sambuc   return ""; // expected-warning {{return' will never be executed}}
224*0a6a1f1dSLionel Sambuc }
225*0a6a1f1dSLionel Sambuc 
trivial_dead_return_char()226*0a6a1f1dSLionel Sambuc char trivial_dead_return_char() {
227*0a6a1f1dSLionel Sambuc   raze();
228*0a6a1f1dSLionel Sambuc   return ' '; // expected-warning {{return' will never be executed}}
229*0a6a1f1dSLionel Sambuc }
230*0a6a1f1dSLionel Sambuc 
nontrivial_dead_return_enum_2(int x)231*0a6a1f1dSLionel Sambuc MyEnum nontrivial_dead_return_enum_2(int x) {
232*0a6a1f1dSLionel Sambuc   switch (x) {
233*0a6a1f1dSLionel Sambuc     case 1: return 1;
234*0a6a1f1dSLionel Sambuc     case 2: return 2;
235*0a6a1f1dSLionel Sambuc     case 3: return 3;
236*0a6a1f1dSLionel Sambuc     default: return 4;
237*0a6a1f1dSLionel Sambuc   }
238*0a6a1f1dSLionel Sambuc 
239*0a6a1f1dSLionel Sambuc   return calledFun(); // expected-warning {{will never be executed}}
240*0a6a1f1dSLionel Sambuc }
241*0a6a1f1dSLionel Sambuc 
242*0a6a1f1dSLionel Sambuc enum X { A, B, C };
243*0a6a1f1dSLionel Sambuc 
covered_switch(enum X x)244*0a6a1f1dSLionel Sambuc int covered_switch(enum X x) {
245*0a6a1f1dSLionel Sambuc   switch (x) {
246*0a6a1f1dSLionel Sambuc   case A: return 1;
247*0a6a1f1dSLionel Sambuc   case B: return 2;
248*0a6a1f1dSLionel Sambuc   case C: return 3;
249*0a6a1f1dSLionel Sambuc   }
250*0a6a1f1dSLionel Sambuc   return 4; // no-warning
251*0a6a1f1dSLionel Sambuc }
252*0a6a1f1dSLionel Sambuc 
253*0a6a1f1dSLionel Sambuc // Test unreachable code depending on configuration values
254*0a6a1f1dSLionel Sambuc #define CONFIG_CONSTANT 1
test_config_constant(int x)255*0a6a1f1dSLionel Sambuc int test_config_constant(int x) {
256*0a6a1f1dSLionel Sambuc   if (!CONFIG_CONSTANT) {
257*0a6a1f1dSLionel Sambuc     calledFun(); // no-warning
258*0a6a1f1dSLionel Sambuc     return 1;
259*0a6a1f1dSLionel Sambuc   }
260*0a6a1f1dSLionel Sambuc   if (!1) { // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
261*0a6a1f1dSLionel Sambuc     calledFun(); // expected-warning {{will never be executed}}
262*0a6a1f1dSLionel Sambuc     return 1;
263*0a6a1f1dSLionel Sambuc   }
264*0a6a1f1dSLionel Sambuc   if (sizeof(int) > sizeof(char)) {
265*0a6a1f1dSLionel Sambuc     calledFun(); // no-warning
266*0a6a1f1dSLionel Sambuc     return 1;
267*0a6a1f1dSLionel Sambuc   }
268*0a6a1f1dSLionel Sambuc   if (x > 10)
269*0a6a1f1dSLionel Sambuc     return CONFIG_CONSTANT ? calledFun() : calledFun(); // no-warning
270*0a6a1f1dSLionel Sambuc   else
271*0a6a1f1dSLionel Sambuc     return 1 ? // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
272*0a6a1f1dSLionel Sambuc       calledFun() :
273*0a6a1f1dSLionel Sambuc       calledFun(); // expected-warning {{will never be executed}}
274*0a6a1f1dSLionel Sambuc }
275*0a6a1f1dSLionel Sambuc 
sizeof_int(int x,int y)276*0a6a1f1dSLionel Sambuc int sizeof_int(int x, int y) {
277*0a6a1f1dSLionel Sambuc   if (sizeof(long) == sizeof(int))
278*0a6a1f1dSLionel Sambuc     return 1; // no-warning
279*0a6a1f1dSLionel Sambuc   if (sizeof(long) != sizeof(int))
280*0a6a1f1dSLionel Sambuc     return 0; // no-warning
281*0a6a1f1dSLionel Sambuc   if (x && y && sizeof(long) < sizeof(char))
282*0a6a1f1dSLionel Sambuc     return 0; // no-warning
283*0a6a1f1dSLionel Sambuc   return 2; // no-warning
284*0a6a1f1dSLionel Sambuc }
285*0a6a1f1dSLionel Sambuc 
286*0a6a1f1dSLionel Sambuc enum MyEnum2 {
287*0a6a1f1dSLionel Sambuc   ME_A = CONFIG_CONSTANT,
288*0a6a1f1dSLionel Sambuc   ME_B = 1
289*0a6a1f1dSLionel Sambuc };
290*0a6a1f1dSLionel Sambuc 
test_MyEnum()291*0a6a1f1dSLionel Sambuc int test_MyEnum() {
292*0a6a1f1dSLionel Sambuc   if (!ME_A)
293*0a6a1f1dSLionel Sambuc     return 1; // no-warning
294*0a6a1f1dSLionel Sambuc   if (ME_A)
295*0a6a1f1dSLionel Sambuc     return 2; // no-warning
296*0a6a1f1dSLionel Sambuc   if (ME_B)
297*0a6a1f1dSLionel Sambuc     return 3;
298*0a6a1f1dSLionel Sambuc   if (!ME_B) // expected-warning {{will never be executed}}
299*0a6a1f1dSLionel Sambuc     return 4; // expected-warning {{will never be executed}}
300*0a6a1f1dSLionel Sambuc   return 5;
301*0a6a1f1dSLionel Sambuc }
302*0a6a1f1dSLionel Sambuc 
303*0a6a1f1dSLionel Sambuc // Test for idiomatic do..while.
test_do_while(int x)304*0a6a1f1dSLionel Sambuc int test_do_while(int x) {
305*0a6a1f1dSLionel Sambuc   do {
306*0a6a1f1dSLionel Sambuc     if (x == calledFun())
307*0a6a1f1dSLionel Sambuc       break;
308*0a6a1f1dSLionel Sambuc     ++x;
309*0a6a1f1dSLionel Sambuc     break;
310*0a6a1f1dSLionel Sambuc   }
311*0a6a1f1dSLionel Sambuc   while (0); // no-warning
312*0a6a1f1dSLionel Sambuc   return x;
313*0a6a1f1dSLionel Sambuc }
314*0a6a1f1dSLionel Sambuc 
test_do_while_nontrivial_cond(int x)315*0a6a1f1dSLionel Sambuc int test_do_while_nontrivial_cond(int x) {
316*0a6a1f1dSLionel Sambuc   do {
317*0a6a1f1dSLionel Sambuc     if (x == calledFun())
318*0a6a1f1dSLionel Sambuc       break;
319*0a6a1f1dSLionel Sambuc     ++x;
320*0a6a1f1dSLionel Sambuc     break;
321*0a6a1f1dSLionel Sambuc   }
322*0a6a1f1dSLionel Sambuc   while (calledFun()); // expected-warning {{will never be executed}}
323*0a6a1f1dSLionel Sambuc   return x;
324*0a6a1f1dSLionel Sambuc }
325*0a6a1f1dSLionel Sambuc 
326*0a6a1f1dSLionel Sambuc // Diagnostic control: -Wunreachable-code-return.
327*0a6a1f1dSLionel Sambuc 
328*0a6a1f1dSLionel Sambuc #pragma clang diagnostic push
329*0a6a1f1dSLionel Sambuc #pragma clang diagnostic ignored "-Wunreachable-code-return"
330*0a6a1f1dSLionel Sambuc 
trivial_dead_return_void_SUPPRESSED()331*0a6a1f1dSLionel Sambuc void trivial_dead_return_void_SUPPRESSED() {
332*0a6a1f1dSLionel Sambuc   raze();
333*0a6a1f1dSLionel Sambuc   return; // no-warning
334*0a6a1f1dSLionel Sambuc }
335*0a6a1f1dSLionel Sambuc 
trivial_dead_return_enum_SUPPRESSED()336*0a6a1f1dSLionel Sambuc MyEnum trivial_dead_return_enum_SUPPRESSED() {
337*0a6a1f1dSLionel Sambuc   raze();
338*0a6a1f1dSLionel Sambuc   return Value1; // no-warning
339*0a6a1f1dSLionel Sambuc }
340*0a6a1f1dSLionel Sambuc 
341*0a6a1f1dSLionel Sambuc #pragma clang diagnostic pop
342*0a6a1f1dSLionel Sambuc 
343*0a6a1f1dSLionel Sambuc // Diagnostic control: -Wunreachable-code-break.
344*0a6a1f1dSLionel Sambuc 
345*0a6a1f1dSLionel Sambuc #pragma clang diagnostic push
346*0a6a1f1dSLionel Sambuc #pragma clang diagnostic ignored "-Wunreachable-code-break"
347*0a6a1f1dSLionel Sambuc 
test_break_preceded_by_noreturn_SUPPRESSED(int i)348*0a6a1f1dSLionel Sambuc int test_break_preceded_by_noreturn_SUPPRESSED(int i) {
349*0a6a1f1dSLionel Sambuc   switch (i) {
350*0a6a1f1dSLionel Sambuc     case 1:
351*0a6a1f1dSLionel Sambuc       raze();
352*0a6a1f1dSLionel Sambuc       break; // no-warning
353*0a6a1f1dSLionel Sambuc     case 2:
354*0a6a1f1dSLionel Sambuc       raze();
355*0a6a1f1dSLionel Sambuc       break; // no-warning
356*0a6a1f1dSLionel Sambuc       warn_here(); // expected-warning {{will never be executed}}
357*0a6a1f1dSLionel Sambuc     case 3:
358*0a6a1f1dSLionel Sambuc       return 1;
359*0a6a1f1dSLionel Sambuc       break; // no-warning
360*0a6a1f1dSLionel Sambuc     default:
361*0a6a1f1dSLionel Sambuc       break;
362*0a6a1f1dSLionel Sambuc       break; // no-warning
363*0a6a1f1dSLionel Sambuc   }
364*0a6a1f1dSLionel Sambuc   return i;
365*0a6a1f1dSLionel Sambuc }
366*0a6a1f1dSLionel Sambuc 
367*0a6a1f1dSLionel Sambuc #pragma clang diagnostic pop
368*0a6a1f1dSLionel Sambuc 
369*0a6a1f1dSLionel Sambuc // Test "silencing" with parentheses.
test_with_paren_silencing(int x)370*0a6a1f1dSLionel Sambuc void test_with_paren_silencing(int x) {
371*0a6a1f1dSLionel Sambuc   if (0) calledFun(); // expected-warning {{will never be executed}} expected-note {{silence by adding parentheses to mark code as explicitly dead}}
372*0a6a1f1dSLionel Sambuc   if ((0)) calledFun(); // no-warning
373*0a6a1f1dSLionel Sambuc 
374*0a6a1f1dSLionel Sambuc   if (1) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
375*0a6a1f1dSLionel Sambuc     calledFun();
376*0a6a1f1dSLionel Sambuc   else
377*0a6a1f1dSLionel Sambuc     calledFun(); // expected-warning {{will never be executed}}
378*0a6a1f1dSLionel Sambuc 
379*0a6a1f1dSLionel Sambuc   if ((1))
380*0a6a1f1dSLionel Sambuc     calledFun();
381*0a6a1f1dSLionel Sambuc   else
382*0a6a1f1dSLionel Sambuc     calledFun(); // no-warning
383*0a6a1f1dSLionel Sambuc 
384*0a6a1f1dSLionel Sambuc   if (!1) // expected-note {{silence by adding parentheses to mark code as explicitly dead}}
385*0a6a1f1dSLionel Sambuc     calledFun(); // expected-warning {{code will never be executed}}
386*0a6a1f1dSLionel Sambuc   else
387*0a6a1f1dSLionel Sambuc     calledFun();
388*0a6a1f1dSLionel Sambuc 
389*0a6a1f1dSLionel Sambuc   if ((!1))
390*0a6a1f1dSLionel Sambuc     calledFun(); // no-warning
391*0a6a1f1dSLionel Sambuc   else
392*0a6a1f1dSLionel Sambuc     calledFun();
393*0a6a1f1dSLionel Sambuc 
394*0a6a1f1dSLionel Sambuc   if (!(1))
395*0a6a1f1dSLionel Sambuc     calledFun(); // no-warning
396*0a6a1f1dSLionel Sambuc   else
397*0a6a1f1dSLionel Sambuc     calledFun();
398*0a6a1f1dSLionel Sambuc }
399