diff options
author | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2015-08-10 07:18:29 +0000 |
---|---|---|
committer | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2015-08-10 07:18:29 +0000 |
commit | 30e2a44a06a4bd61f9c607e0d7e2447e0dc488db (patch) | |
tree | 79dee54f4fec6a87e80b9b5ac8f2a92aaff4a4ce /clang/test/Analysis/identical-expressions.cpp | |
parent | 001e2e42286ac0ed98577ad3f4e99fbd15760f6b (diff) | |
download | bcm5719-llvm-30e2a44a06a4bd61f9c607e0d7e2447e0dc488db.tar.gz bcm5719-llvm-30e2a44a06a4bd61f9c607e0d7e2447e0dc488db.zip |
[Static Analyzer] Warn when inner and outer conditions are identical. The inner condition is always true.
Reviewed in http://reviews.llvm.org/D10892.
llvm-svn: 244435
Diffstat (limited to 'clang/test/Analysis/identical-expressions.cpp')
-rw-r--r-- | clang/test/Analysis/identical-expressions.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/test/Analysis/identical-expressions.cpp b/clang/test/Analysis/identical-expressions.cpp index 46dd56289c4..138cd7ce988 100644 --- a/clang/test/Analysis/identical-expressions.cpp +++ b/clang/test/Analysis/identical-expressions.cpp @@ -1530,3 +1530,35 @@ void test_nowarn_long() { c = 0LL; } } + +// Identical inner conditions + +void test_warn_inner_if_1(int x) { + if (x == 1) { + if (x == 1) // expected-warning {{conditions of the inner and outer statements are identical}} + ; + } + + // FIXME: Should warn here. The warning is currently not emitted because there + // is code between the conditions. + if (x == 1) { + int y = x; + if (x == 1) + ; + } +} + +void test_nowarn_inner_if_1(int x) { + // Don't warn when condition has side effects. + if (x++ == 1) { + if (x++ == 1) + ; + } + + // Don't warn when x is changed before inner condition. + if (x < 10) { + x++; + if (x < 10) + ; + } +} |