diff options
Diffstat (limited to 'test/Sema/warn-unreachable.c')
-rw-r--r-- | test/Sema/warn-unreachable.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/Sema/warn-unreachable.c b/test/Sema/warn-unreachable.c index 34e0296a20490..440aa0a5a174c 100644 --- a/test/Sema/warn-unreachable.c +++ b/test/Sema/warn-unreachable.c @@ -451,3 +451,50 @@ void unaryOpFixitCastSubExpr(int x) { // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:")" unaryOpFixitCastSubExpr(x); // expected-warning {{code will never be executed}} } + +#define false 0 +#define true 1 + +void testTrueFalseMacros() { + if (false) // expected-note {{silence by adding parentheses to mark code as explicitly dead}} + testTrueFalseMacros(); // expected-warning {{code will never be executed}} + if (!true) // expected-note {{silence by adding parentheses to mark code as explicitly dead}} + testTrueFalseMacros(); // expected-warning {{code will never be executed}} +} + +int pr13910_foo(int x) { + if (x == 1) + return 0; + else + return x; + __builtin_unreachable(); // expected no warning +} + +int pr13910_bar(int x) { + switch (x) { + default: + return x + 1; + } + pr13910_foo(x); // expected-warning {{code will never be executed}} +} + +int pr13910_bar2(int x) { + if (x == 1) + return 0; + else + return x; + pr13910_foo(x); // expected-warning {{code will never be executed}} + __builtin_unreachable(); // expected no warning + pr13910_foo(x); // expected-warning {{code will never be executed}} +} + +void pr13910_noreturn() { + raze(); + __builtin_unreachable(); // expected no warning +} + +void pr13910_assert() { + myassert(0 && "unreachable"); + return; + __builtin_unreachable(); // expected no warning +} |