summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/identical-expressions.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2014-02-19 17:44:16 +0000
committerJordan Rose <jordan_rose@apple.com>2014-02-19 17:44:16 +0000
commit94008121fafecdf89f83a63249496e185bc9cd77 (patch)
tree5a97bc807e931785a2e9722743a18db748c4dc81 /clang/test/Analysis/identical-expressions.cpp
parent70e7e8718e14f8c29ff57c4c7e2fe07ad226ec36 (diff)
downloadbcm5719-llvm-94008121fafecdf89f83a63249496e185bc9cd77.tar.gz
bcm5719-llvm-94008121fafecdf89f83a63249496e185bc9cd77.zip
[analyzer] Extend IdenticalExprChecker to check logical and bitwise expressions.
IdenticalExprChecker now warns if any expressions in a logical or bitwise chain (&&, ||, &, |, or ^) are the same. Unlike the previous patch, this actually checks all subexpressions against each other (an O(N^2) operation, but N is likely to be small). Patch by Daniel Fahlgren! llvm-svn: 201702
Diffstat (limited to 'clang/test/Analysis/identical-expressions.cpp')
-rw-r--r--clang/test/Analysis/identical-expressions.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/clang/test/Analysis/identical-expressions.cpp b/clang/test/Analysis/identical-expressions.cpp
index acb7c8c57b0..950cdd93ff4 100644
--- a/clang/test/Analysis/identical-expressions.cpp
+++ b/clang/test/Analysis/identical-expressions.cpp
@@ -1309,3 +1309,89 @@ void test_identical_branches_if(bool b, int i) {
i += 10;
}
}
+
+void test_identical_bitwise1() {
+ int a = 5 | 5; // expected-warning {{identical expressions on both sides of bitwise operator}}
+}
+
+void test_identical_bitwise2() {
+ int a = 5;
+ int b = a | a; // expected-warning {{identical expressions on both sides of bitwise operator}}
+}
+
+void test_identical_bitwise3() {
+ int a = 5;
+ int b = (a | a); // expected-warning {{identical expressions on both sides of bitwise operator}}
+}
+
+void test_identical_bitwise4() {
+ int a = 4;
+ int b = a | 4; // no-warning
+}
+
+void test_identical_bitwise5() {
+ int a = 4;
+ int b = 4;
+ int c = a | b; // no-warning
+}
+
+void test_identical_bitwise6() {
+ int a = 5;
+ int b = a | 4 | a; // expected-warning {{identical expressions on both sides of bitwise operator}}
+}
+
+void test_identical_bitwise7() {
+ int a = 5;
+ int b = func() | func(); // no-warning
+}
+
+void test_identical_logical1(int a) {
+ if (a == 4 && a == 4) // expected-warning {{identical expressions on both sides of logical operator}}
+ ;
+}
+
+void test_identical_logical2(int a) {
+ if (a == 4 || a == 5 || a == 4) // expected-warning {{identical expressions on both sides of logical operator}}
+ ;
+}
+
+void test_identical_logical3(int a) {
+ if (a == 4 || a == 5 || a == 6) // no-warning
+ ;
+}
+
+void test_identical_logical4(int a) {
+ if (a == func() || a == func()) // no-warning
+ ;
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wlogical-op-parentheses"
+void test_identical_logical5(int x, int y) {
+ if (x == 4 && y == 5 || x == 4 && y == 6) // no-warning
+ ;
+}
+
+void test_identical_logical6(int x, int y) {
+ if (x == 4 && y == 5 || x == 4 && y == 5) // expected-warning {{identical expressions on both sides of logical operator}}
+ ;
+}
+
+void test_identical_logical7(int x, int y) {
+ // FIXME: We should warn here
+ if (x == 4 && y == 5 || x == 4)
+ ;
+}
+
+void test_identical_logical8(int x, int y) {
+ // FIXME: We should warn here
+ if (x == 4 || y == 5 && x == 4)
+ ;
+}
+
+void test_identical_logical9(int x, int y) {
+ // FIXME: We should warn here
+ if (x == 4 || x == 4 && y == 5)
+ ;
+}
+#pragma clang diagnostic pop
OpenPOWER on IntegriCloud