diff options
author | Jordan Rose <jordan_rose@apple.com> | 2014-03-11 16:52:29 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2014-03-11 16:52:29 +0000 |
commit | a6839aaa9bd7c75665263a558796d9d10ec89442 (patch) | |
tree | 531b63fb09b9380d52fcc43230fa855cb74dc4a1 /clang/test/Analysis/identical-expressions.cpp | |
parent | b70830612848919416ec1058b2724956e5dd39b5 (diff) | |
download | bcm5719-llvm-a6839aaa9bd7c75665263a558796d9d10ec89442.tar.gz bcm5719-llvm-a6839aaa9bd7c75665263a558796d9d10ec89442.zip |
[analyzer] Check all conditions in a chained if against each other.
Like the binary operator check of r201702, this actually checks the
condition of every if in a chain against every other condition, an
O(N^2) operation. In most cases N should be small enough to make this
practical, and checking all cases like this makes it much more likely
to catch a copy-paste error within the same series of branches.
Part of IdenticalExprChecker; patch by Daniel Fahlgren!
llvm-svn: 203585
Diffstat (limited to 'clang/test/Analysis/identical-expressions.cpp')
-rw-r--r-- | clang/test/Analysis/identical-expressions.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/clang/test/Analysis/identical-expressions.cpp b/clang/test/Analysis/identical-expressions.cpp index e1f51af7c6f..85e3322002d 100644 --- a/clang/test/Analysis/identical-expressions.cpp +++ b/clang/test/Analysis/identical-expressions.cpp @@ -1406,3 +1406,108 @@ void test_identical_logical9(int x, int y) { ; } #pragma clang diagnostic pop + +void test_warn_chained_if_stmts_1(int x) { + if (x == 1) + ; + else if (x == 1) // expected-warning {{expression is identical to previous condition}} + ; +} + +void test_warn_chained_if_stmts_2(int x) { + if (x == 1) + ; + else if (x == 1) // expected-warning {{expression is identical to previous condition}} + ; + else if (x == 1) // expected-warning {{expression is identical to previous condition}} + ; +} + +void test_warn_chained_if_stmts_3(int x) { + if (x == 1) + ; + else if (x == 2) + ; + else if (x == 1) // expected-warning {{expression is identical to previous condition}} + ; +} + +void test_warn_chained_if_stmts_4(int x) { + if (x == 1) + ; + else if (func()) + ; + else if (x == 1) // expected-warning {{expression is identical to previous condition}} + ; +} + +void test_warn_chained_if_stmts_5(int x) { + if (x & 1) + ; + else if (x & 1) // expected-warning {{expression is identical to previous condition}} + ; +} + +void test_warn_chained_if_stmts_6(int x) { + if (x == 1) + ; + else if (x == 2) + ; + else if (x == 2) // expected-warning {{expression is identical to previous condition}} + ; + else if (x == 3) + ; +} + +void test_warn_chained_if_stmts_7(int x) { + if (x == 1) + ; + else if (x == 2) + ; + else if (x == 3) + ; + else if (x == 2) // expected-warning {{expression is identical to previous condition}} + ; + else if (x == 5) + ; +} + +void test_warn_chained_if_stmts_8(int x) { + if (x == 1) + ; + else if (x == 2) + ; + else if (x == 3) + ; + else if (x == 2) // expected-warning {{expression is identical to previous condition}} + ; + else if (x == 5) + ; + else if (x == 3) // expected-warning {{expression is identical to previous condition}} + ; + else if (x == 7) + ; +} + +void test_nowarn_chained_if_stmts_1(int x) { + if (func()) + ; + else if (func()) // no-warning + ; +} + +void test_nowarn_chained_if_stmts_2(int x) { + if (func()) + ; + else if (x == 1) + ; + else if (func()) // no-warning + ; +} + +void test_nowarn_chained_if_stmts_3(int x) { + if (x++) + ; + else if (x++) // no-warning + ; +} |