1 // RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value -Wno-covered-switch-default
3 int halt() __attribute__((noreturn));
10 goto e; // expected-warning {{will never be executed}}
14 goto b; // expected-warning {{will never be executed}}
15 goto a; // expected-warning {{will never be executed}}
31 dead(); // expected-warning {{will never be executed}}
35 dead(); // expected-warning {{will never be executed}}
39 + // expected-warning {{will never be executed}}
47 goto a4; // expected-warning {{will never be executed}}
52 dead(); // expected-warning {{will never be executed}}
66 dead(); // expected-warning {{will never be executed}}
79 dead(); // expected-warning {{will never be executed}}
80 - // expected-warning {{will never be executed}}
83 i // expected-warning {{will never be executed}}
88 ? // expected-warning {{will never be executed}}
91 ( // expected-warning {{will never be executed}}
96 a[halt() // expected-warning {{will never be executed}}
102 enum Cases { C1, C2, C3 };
103 int test_enum_cases(enum Cases C) {
110 int i = 0; // expected-warning{{will never be executed}}
117 // Handle unreachable code triggered by macro expansions.
118 void __myassert_rtn(const char *, const char *, int, const char *) __attribute__((__noreturn__));
120 #define myassert(e) \
121 (__builtin_expect(!(e), 0) ? __myassert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
124 myassert(0 && "unreachable");
125 return; // no-warning
128 // Test case for PR 9774. Tests that dead code in macros aren't warned about.
129 #define MY_MAX(a,b) ((a) >= (b) ? (a) : (b))
130 void PR9774(int *s) {
131 for (int i = 0; i < MY_MAX(2, 3); i++) // no-warning
135 // Test case for <rdar://problem/11005770>. We should treat code guarded
136 // by 'x & 0' and 'x * 0' as unreachable.
138 void test_mul_and_zero(int x) {
139 if (x & 0) calledFun(); // expected-warning {{will never be executed}}
140 if (0 & x) calledFun(); // expected-warning {{will never be executed}}
141 if (x * 0) calledFun(); // expected-warning {{will never be executed}}
142 if (0 * x) calledFun(); // expected-warning {{will never be executed}}