diff options
author | Ted Kremenek <kremenek@apple.com> | 2014-03-06 00:17:44 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2014-03-06 00:17:44 +0000 |
commit | 1de2e14f2f3a0f703298f111146f61fbaec1b752 (patch) | |
tree | 664e3b3d2b9d324241dc76325447e2cd6fcee1c1 /clang/test/Sema/warn-unreachable.c | |
parent | 4b047f23789699e1edde508a548ad04a9fed001b (diff) | |
download | bcm5719-llvm-1de2e14f2f3a0f703298f111146f61fbaec1b752.tar.gz bcm5719-llvm-1de2e14f2f3a0f703298f111146f61fbaec1b752.zip |
[-Wunreachable-code] Handle idiomatic do...while() with an uninteresting condition.
Sometimes do..while() is used to create a scope that can be left early.
In such cases, the unreachable 'while()' test is not usually interesting
unless it actually does something that is observable.
llvm-svn: 203036
Diffstat (limited to 'clang/test/Sema/warn-unreachable.c')
-rw-r--r-- | clang/test/Sema/warn-unreachable.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/clang/test/Sema/warn-unreachable.c b/clang/test/Sema/warn-unreachable.c index 3c6d891613a..bf1e9137eb2 100644 --- a/clang/test/Sema/warn-unreachable.c +++ b/clang/test/Sema/warn-unreachable.c @@ -268,9 +268,31 @@ int test_MyEnum() { return 2; // no-warning if (ME_B) return 3; - // FIXME: we should only need one diagnostic here. if (!ME_B) // expected-warning {{will never be executed}} - return 4;// expected-warning {{will never be executed}} + return 4; // expected-warning {{will never be executed}} return 5; } +// Test for idiomatic do..while. +int test_do_while(int x) { + do { + if (x == calledFun()) + break; + ++x; + break; + } + while (0); // no-warning + return x; +} + +int test_do_while_nontrivial_cond(int x) { + do { + if (x == calledFun()) + break; + ++x; + break; + } + while (calledFun()); // expected-warning {{will never be executed}} + return x; +} + |