1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.IdenticalExpr -w -verify %s
3 /* Only one expected warning per function allowed at the very end. */
23 int checkNotEqualFloatLiteralCompare1(void) {
24 return (5.14F != 5.14F); // no warning
27 int checkNotEqualFloatLiteralCompare2(void) {
28 return (6.14F != 7.14F); // no warning
31 int checkNotEqualFloatDeclCompare1(void) {
34 return (f != g); // no warning
37 int checkNotEqualFloatDeclCompare12(void) {
39 return (f != f); // no warning
42 int checkNotEqualFloatDeclCompare3(void) {
44 return (f != 7.1F); // no warning
47 int checkNotEqualFloatDeclCompare4(void) {
49 return (7.1F != f); // no warning
52 int checkNotEqualFloatDeclCompare5(void) {
55 return (t != f); // no warning
58 int checkNotEqualFloatDeclCompare6(void) {
61 return (f != t); // no warning
66 int checkNotEqualCastFloatDeclCompare11(void) {
68 return ((int)f != (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
70 int checkNotEqualCastFloatDeclCompare12(void) {
72 return ((char)f != (int)f); // no warning
74 int checkNotEqualBinaryOpFloatCompare1(void) {
77 res = (f + 3.14F != f + 3.14F); // no warning
80 int checkNotEqualBinaryOpFloatCompare2(void) {
83 return (f + 3.14F != g + 3.14F); // no warning
85 int checkNotEqualBinaryOpFloatCompare3(void) {
88 res = ((int)f + 3.14F != (int)f + 3.14F); // no warning
91 int checkNotEqualBinaryOpFloatCompare4(void) {
94 res = ((int)f + 3.14F != (char)f + 3.14F); // no warning
98 int checkNotEqualNestedBinaryOpFloatCompare1(void) {
103 res = (((int)f + (3.14F - u)*t) != ((int)f + (3.14F - u)*t)); // no warning
107 int checkNotEqualNestedBinaryOpFloatCompare2(void) {
112 res = (((int)f + (u - 3.14F)*t) != ((int)f + (3.14F - u)*t)); // no warning
116 int checkNotEqualNestedBinaryOpFloatCompare3(void) {
121 res = (((int)f + (u - 3.14F)*t) != ((int)f + (3.14F - u)*(f + t != f + t))); // no warning
128 /* end '!=' with float*/
132 int checkNotEqualIntLiteralCompare1(void) {
133 return (5 != 5); // expected-warning {{comparison of identical expressions always evaluates to false}}
136 int checkNotEqualIntLiteralCompare2(void) {
137 return (6 != 7); // no warning
140 int checkNotEqualIntDeclCompare1(void) {
143 return (f != g); // no warning
146 int checkNotEqualIntDeclCompare3(void) {
148 return (f != 7); // no warning
151 int checkNotEqualIntDeclCompare4(void) {
153 return (7 != f); // no warning
156 int checkNotEqualCastIntDeclCompare11(void) {
158 return ((int)f != (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
160 int checkNotEqualCastIntDeclCompare12(void) {
162 return ((char)f != (int)f); // no warning
164 int checkNotEqualBinaryOpIntCompare1(void) {
169 res = (f + 4 != f + 4); // expected-warning {{comparison of identical expressions always evaluates to false}}
172 int checkNotEqualBinaryOpIntCompare2(void) {
175 return (f + 4 != g + 4); // no warning
179 int checkNotEqualBinaryOpIntCompare3(void) {
184 res = ((int)f + 4 != (int)f + 4); // expected-warning {{comparison of identical expressions always evaluates to false}}
187 int checkNotEqualBinaryOpIntCompare4(void) {
192 res = ((int)f + 4 != (char)f + 4); // no warning
195 int checkNotEqualBinaryOpIntCompare5(void) {
199 res = (u + t != u + t); // expected-warning {{comparison of identical expressions always evaluates to false}}
203 int checkNotEqualNestedBinaryOpIntCompare1(void) {
208 res = (((int)f + (3 - u)*t) != ((int)f + (3 - u)*t)); // expected-warning {{comparison of identical expressions always evaluates to false}}
212 int checkNotEqualNestedBinaryOpIntCompare2(void) {
217 res = (((int)f + (u - 3)*t) != ((int)f + (3 - u)*t)); // no warning
221 int checkNotEqualNestedBinaryOpIntCompare3(void) {
226 res = (((int)f + (u - 3)*t) != ((int)f + (3 - u)*(t + 1 != t + 1))); // expected-warning {{comparison of identical expressions always evaluates to false}}
234 /* '!=' with int pointer */
236 int checkNotEqualIntPointerLiteralCompare1(void) {
238 return (p != 0); // no warning
241 int checkNotEqualIntPointerLiteralCompare2(void) {
242 return (6 != 7); // no warning
245 int checkNotEqualIntPointerDeclCompare1(void) {
249 return (f != g); // no warning
252 int checkNotEqualCastIntPointerDeclCompare11(void) {
255 return ((int*)f != (int*)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
257 int checkNotEqualCastIntPointerDeclCompare12(void) {
260 return ((int*)((char*)f) != (int*)f); // no warning
262 int checkNotEqualBinaryOpIntPointerCompare1(void) {
266 res = (f + 4 != f + 4); // expected-warning {{comparison of identical expressions always evaluates to false}}
269 int checkNotEqualBinaryOpIntPointerCompare2(void) {
273 return (f + 4 != g + 4); // no warning
277 int checkNotEqualBinaryOpIntPointerCompare3(void) {
281 res = ((int*)f + 4 != (int*)f + 4); // expected-warning {{comparison of identical expressions always evaluates to false}}
284 int checkNotEqualBinaryOpIntPointerCompare4(void) {
288 res = ((int*)f + 4 != (int*)((char*)f) + 4); // no warning
292 int checkNotEqualNestedBinaryOpIntPointerCompare1(void) {
298 res = ((f + (3)*t) != (f + (3)*t)); // expected-warning {{comparison of identical expressions always evaluates to false}}
302 int checkNotEqualNestedBinaryOpIntPointerCompare2(void) {
308 res = (((3)*t + f) != (f + (3)*t)); // no warning
313 /* '!=' with function*/
315 int checkNotEqualSameFunction() {
318 int res = (a+func() != a+func()); // no warning
322 int checkNotEqualDifferentFunction() {
325 int res = (a+func() != a+func2()); // no warning
329 int checkNotEqualSameFunctionSameParam() {
332 int res = (a+funcParam(a) != a+funcParam(a)); // no warning
336 int checkNotEqualSameFunctionDifferentParam() {
339 int res = (a+funcParam(a) != a+funcParam(b)); // no warning
343 /* end '!=' with function*/
351 int checkEqualIntPointerDeclCompare(void) {
355 return (f == g); // no warning
358 int checkEqualIntPointerDeclCompare0(void) {
361 return (f+1 == f+1); // expected-warning {{comparison of identical expressions always evaluates to true}}
366 int checkEqualFloatLiteralCompare1(void) {
367 return (5.14F == 5.14F); // no warning
370 int checkEqualFloatLiteralCompare2(void) {
371 return (6.14F == 7.14F); // no warning
374 int checkEqualFloatDeclCompare1(void) {
377 return (f == g); // no warning
380 int checkEqualFloatDeclCompare12(void) {
382 return (f == f); // no warning
386 int checkEqualFloatDeclCompare3(void) {
388 return (f == 7.1F); // no warning
391 int checkEqualFloatDeclCompare4(void) {
393 return (7.1F == f); // no warning
396 int checkEqualFloatDeclCompare5(void) {
399 return (t == f); // no warning
402 int checkEqualFloatDeclCompare6(void) {
405 return (f == t); // no warning
411 int checkEqualCastFloatDeclCompare11(void) {
413 return ((int)f == (int)f); // expected-warning {{comparison of identical expressions always evaluates to true}}
415 int checkEqualCastFloatDeclCompare12(void) {
417 return ((char)f == (int)f); // no warning
419 int checkEqualBinaryOpFloatCompare1(void) {
422 res = (f + 3.14F == f + 3.14F); // no warning
425 int checkEqualBinaryOpFloatCompare2(void) {
428 return (f + 3.14F == g + 3.14F); // no warning
430 int checkEqualBinaryOpFloatCompare3(void) {
433 res = ((int)f + 3.14F == (int)f + 3.14F); // no warning
436 int checkEqualBinaryOpFloatCompare4(void) {
439 res = ((int)f + 3.14F == (char)f + 3.14F); // no warning
443 int checkEqualNestedBinaryOpFloatCompare1(void) {
448 res = (((int)f + (3.14F - u)*t) == ((int)f + (3.14F - u)*t)); // no warning
452 int checkEqualNestedBinaryOpFloatCompare2(void) {
457 res = (((int)f + (u - 3.14F)*t) == ((int)f + (3.14F - u)*t)); // no warning
461 int checkEqualNestedBinaryOpFloatCompare3(void) {
466 res = (((int)f + (u - 3.14F)*t) == ((int)f + (3.14F - u)*(f + t == f + t))); // no warning
476 int checkEqualIntLiteralCompare1(void) {
477 return (5 == 5); // expected-warning {{comparison of identical expressions always evaluates to true}}
480 int checkEqualIntLiteralCompare2(void) {
481 return (6 == 7); // no warning
484 int checkEqualIntDeclCompare1(void) {
487 return (f == g); // no warning
490 int checkEqualCastIntDeclCompare11(void) {
492 return ((int)f == (int)f); // expected-warning {{comparison of identical expressions always evaluates to true}}
494 int checkEqualCastIntDeclCompare12(void) {
496 return ((char)f == (int)f); // no warning
499 int checkEqualIntDeclCompare3(void) {
501 return (f == 7); // no warning
504 int checkEqualIntDeclCompare4(void) {
506 return (7 == f); // no warning
509 int checkEqualBinaryOpIntCompare1(void) {
514 res = (f + 4 == f + 4); // expected-warning {{comparison of identical expressions always evaluates to true}}
517 int checkEqualBinaryOpIntCompare2(void) {
520 return (f + 4 == g + 4); // no warning
524 int checkEqualBinaryOpIntCompare3(void) {
529 res = ((int)f + 4 == (int)f + 4); // expected-warning {{comparison of identical expressions always evaluates to true}}
533 int checkEqualBinaryOpIntCompare4(void) {
538 res = ((int)f + 4 == (char)f + 4); // no warning
541 int checkEqualBinaryOpIntCompare5(void) {
545 res = (u + t == u + t); // expected-warning {{comparison of identical expressions always evaluates to true}}
549 int checkEqualNestedBinaryOpIntCompare1(void) {
554 res = (((int)f + (3 - u)*t) == ((int)f + (3 - u)*t)); // expected-warning {{comparison of identical expressions always evaluates to true}}
558 int checkEqualNestedBinaryOpIntCompare2(void) {
563 res = (((int)f + (u - 3)*t) == ((int)f + (3 - u)*t)); // no warning
567 int checkEqualNestedBinaryOpIntCompare3(void) {
572 res = (((int)f + (u - 3)*t) == ((int)f + (3 - u)*(t + 1 == t + 1))); // expected-warning {{comparison of identical expressions always evaluates to true}}
576 /* '==' with function*/
578 int checkEqualSameFunction() {
581 int res = (a+func() == a+func()); // no warning
585 int checkEqualDifferentFunction() {
588 int res = (a+func() == a+func2()); // no warning
592 int checkEqualSameFunctionSameParam() {
595 int res = (a+funcParam(a) == a+funcParam(a)); // no warning
599 int checkEqualSameFunctionDifferentParam() {
602 int res = (a+funcParam(a) == a+funcParam(b)); // no warning
606 /* end '==' with function*/
617 int checkLessThanFloatLiteralCompare1(void) {
618 return (5.14F < 5.14F); // expected-warning {{comparison of identical expressions always evaluates to false}}
621 int checkLessThanFloatLiteralCompare2(void) {
622 return (6.14F < 7.14F); // no warning
625 int checkLessThanFloatDeclCompare1(void) {
628 return (f < g); // no warning
631 int checkLessThanFloatDeclCompare12(void) {
633 return (f < f); // expected-warning {{comparison of identical expressions always evaluates to false}}
636 int checkLessThanFloatDeclCompare3(void) {
638 return (f < 7.1F); // no warning
641 int checkLessThanFloatDeclCompare4(void) {
643 return (7.1F < f); // no warning
646 int checkLessThanFloatDeclCompare5(void) {
649 return (t < f); // no warning
652 int checkLessThanFloatDeclCompare6(void) {
655 return (f < t); // no warning
659 int checkLessThanCastFloatDeclCompare11(void) {
661 return ((int)f < (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
663 int checkLessThanCastFloatDeclCompare12(void) {
665 return ((char)f < (int)f); // no warning
667 int checkLessThanBinaryOpFloatCompare1(void) {
670 res = (f + 3.14F < f + 3.14F); // no warning
673 int checkLessThanBinaryOpFloatCompare2(void) {
676 return (f + 3.14F < g + 3.14F); // no warning
678 int checkLessThanBinaryOpFloatCompare3(void) {
681 res = ((int)f + 3.14F < (int)f + 3.14F); // no warning
684 int checkLessThanBinaryOpFloatCompare4(void) {
687 res = ((int)f + 3.14F < (char)f + 3.14F); // no warning
691 int checkLessThanNestedBinaryOpFloatCompare1(void) {
696 res = (((int)f + (3.14F - u)*t) < ((int)f + (3.14F - u)*t)); // no warning
700 int checkLessThanNestedBinaryOpFloatCompare2(void) {
705 res = (((int)f + (u - 3.14F)*t) < ((int)f + (3.14F - u)*t)); // no warning
709 int checkLessThanNestedBinaryOpFloatCompare3(void) {
714 res = (((int)f + (u - 3.14F)*t) < ((int)f + (3.14F - u)*(f + t < f + t))); // no warning
718 /* end LT with float */
723 int checkLessThanIntLiteralCompare1(void) {
724 return (5 < 5); // expected-warning {{comparison of identical expressions always evaluates to false}}
727 int checkLessThanIntLiteralCompare2(void) {
728 return (6 < 7); // no warning
731 int checkLessThanIntDeclCompare1(void) {
734 return (f < g); // no warning
737 int checkLessThanIntDeclCompare3(void) {
739 return (f < 7); // no warning
742 int checkLessThanIntDeclCompare4(void) {
744 return (7 < f); // no warning
747 int checkLessThanIntDeclCompare5(void) {
750 return (t < f); // no warning
753 int checkLessThanIntDeclCompare6(void) {
756 return (f < t); // no warning
759 int checkLessThanCastIntDeclCompare11(void) {
761 return ((int)f < (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
763 int checkLessThanCastIntDeclCompare12(void) {
765 return ((char)f < (int)f); // no warning
767 int checkLessThanBinaryOpIntCompare1(void) {
770 res = (f + 3 < f + 3); // expected-warning {{comparison of identical expressions always evaluates to false}}
773 int checkLessThanBinaryOpIntCompare2(void) {
776 return (f + 3 < g + 3); // no warning
778 int checkLessThanBinaryOpIntCompare3(void) {
781 res = ((int)f + 3 < (int)f + 3); // expected-warning {{comparison of identical expressions always evaluates to false}}
784 int checkLessThanBinaryOpIntCompare4(void) {
787 res = ((int)f + 3 < (char)f + 3); // no warning
791 int checkLessThanNestedBinaryOpIntCompare1(void) {
796 res = (((int)f + (3 - u)*t) < ((int)f + (3 - u)*t)); // expected-warning {{comparison of identical expressions always evaluates to false}}
800 int checkLessThanNestedBinaryOpIntCompare2(void) {
805 res = (((int)f + (u - 3)*t) < ((int)f + (3 - u)*t)); // no warning
809 int checkLessThanNestedBinaryOpIntCompare3(void) {
814 res = (((int)f + (u - 3)*t) < ((int)f + (3 - u)*(t + u < t + u))); // expected-warning {{comparison of identical expressions always evaluates to false}}
818 /* end LT with int */
827 int checkGreaterThanFloatLiteralCompare1(void) {
828 return (5.14F > 5.14F); // expected-warning {{comparison of identical expressions always evaluates to false}}
831 int checkGreaterThanFloatLiteralCompare2(void) {
832 return (6.14F > 7.14F); // no warning
835 int checkGreaterThanFloatDeclCompare1(void) {
839 return (f > g); // no warning
842 int checkGreaterThanFloatDeclCompare12(void) {
844 return (f > f); // expected-warning {{comparison of identical expressions always evaluates to false}}
848 int checkGreaterThanFloatDeclCompare3(void) {
850 return (f > 7.1F); // no warning
853 int checkGreaterThanFloatDeclCompare4(void) {
855 return (7.1F > f); // no warning
858 int checkGreaterThanFloatDeclCompare5(void) {
861 return (t > f); // no warning
864 int checkGreaterThanFloatDeclCompare6(void) {
867 return (f > t); // no warning
870 int checkGreaterThanCastFloatDeclCompare11(void) {
872 return ((int)f > (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
874 int checkGreaterThanCastFloatDeclCompare12(void) {
876 return ((char)f > (int)f); // no warning
878 int checkGreaterThanBinaryOpFloatCompare1(void) {
881 res = (f + 3.14F > f + 3.14F); // no warning
884 int checkGreaterThanBinaryOpFloatCompare2(void) {
887 return (f + 3.14F > g + 3.14F); // no warning
889 int checkGreaterThanBinaryOpFloatCompare3(void) {
892 res = ((int)f + 3.14F > (int)f + 3.14F); // no warning
895 int checkGreaterThanBinaryOpFloatCompare4(void) {
898 res = ((int)f + 3.14F > (char)f + 3.14F); // no warning
902 int checkGreaterThanNestedBinaryOpFloatCompare1(void) {
907 res = (((int)f + (3.14F - u)*t) > ((int)f + (3.14F - u)*t)); // no warning
911 int checkGreaterThanNestedBinaryOpFloatCompare2(void) {
916 res = (((int)f + (u - 3.14F)*t) > ((int)f + (3.14F - u)*t)); // no warning
920 int checkGreaterThanNestedBinaryOpFloatCompare3(void) {
925 res = (((int)f + (u - 3.14F)*t) > ((int)f + (3.14F - u)*(f + t > f + t))); // no warning
929 /* end GT with float */
934 int checkGreaterThanIntLiteralCompare1(void) {
935 return (5 > 5); // expected-warning {{comparison of identical expressions always evaluates to false}}
938 int checkGreaterThanIntLiteralCompare2(void) {
939 return (6 > 7); // no warning
942 int checkGreaterThanIntDeclCompare1(void) {
946 return (f > g); // no warning
949 int checkGreaterThanIntDeclCompare3(void) {
951 return (f > 7); // no warning
954 int checkGreaterThanIntDeclCompare4(void) {
956 return (7 > f); // no warning
959 int checkGreaterThanCastIntDeclCompare11(void) {
961 return ((int)f > (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
963 int checkGreaterThanCastIntDeclCompare12(void) {
965 return ((char)f > (int)f); // no warning
967 int checkGreaterThanBinaryOpIntCompare1(void) {
970 res = (f + 3 > f + 3); // expected-warning {{comparison of identical expressions always evaluates to false}}
973 int checkGreaterThanBinaryOpIntCompare2(void) {
976 return (f + 3 > g + 3); // no warning
978 int checkGreaterThanBinaryOpIntCompare3(void) {
981 res = ((int)f + 3 > (int)f + 3); // expected-warning {{comparison of identical expressions always evaluates to false}}
984 int checkGreaterThanBinaryOpIntCompare4(void) {
987 res = ((int)f + 3 > (char)f + 3); // no warning
991 int checkGreaterThanNestedBinaryOpIntCompare1(void) {
996 res = (((int)f + (3 - u)*t) > ((int)f + (3 - u)*t)); // expected-warning {{comparison of identical expressions always evaluates to false}}
1000 int checkGreaterThanNestedBinaryOpIntCompare2(void) {
1005 res = (((int)f + (u - 3)*t) > ((int)f + (3 - u)*t)); // no warning
1009 int checkGreaterThanNestedBinaryOpIntCompare3(void) {
1014 res = (((int)f + (u - 3)*t) > ((int)f + (3 - u)*(t + u > t + u))); // expected-warning {{comparison of identical expressions always evaluates to false}}
1018 /* end GT with int */
1023 /* Checking use of identical expressions in conditional operator*/
1025 unsigned test_unsigned(unsigned a) {
1027 a = a > 5 ? b : b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1031 void test_signed() {
1033 a = a > 5 ? a : a; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1036 void test_bool(bool a) {
1037 a = a > 0 ? a : a; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1043 a = a > 5 ? a : a; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1046 const char *test_string() {
1048 return a > 5 ? "abc" : "abc"; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1051 void test_unsigned_expr() {
1054 a = a > 5 ? a+b : a+b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1057 void test_signed_expr() {
1060 a = a > 5 ? a+b : a+b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1063 void test_bool_expr(bool a) {
1065 a = a > 0 ? a&&b : a&&b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1068 void test_unsigned_expr_negative() {
1071 a = a > 5 ? a+b : b+a; // no warning
1074 void test_signed_expr_negative() {
1077 a = a > 5 ? b+a : a+b; // no warning
1080 void test_bool_expr_negative(bool a) {
1082 a = a > 0 ? a&&b : b&&a; // no warning
1085 void test_float_expr_positive() {
1088 a = a > 5 ? a+b : a+b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1091 void test_expr_positive_func() {
1094 a = a > 5 ? a+func() : a+func(); // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1097 void test_expr_negative_func() {
1100 a = a > 5 ? a+func() : a+func2(); // no warning
1103 void test_expr_positive_funcParam() {
1106 a = a > 5 ? a+funcParam(b) : a+funcParam(b); // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1109 void test_expr_negative_funcParam() {
1112 a = a > 5 ? a+funcParam(a) : a+funcParam(b); // no warning
1115 void test_expr_positive_inc() {
1118 a = a > 5 ? a++ : a++; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1121 void test_expr_negative_inc() {
1124 a = a > 5 ? a++ : b++; // no warning
1127 void test_expr_positive_assign() {
1130 a = a > 5 ? a=1 : a=1; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1133 void test_expr_negative_assign() {
1136 a = a > 5 ? a=1 : a=2; // no warning
1139 void test_signed_nested_expr() {
1143 a = a > 5 ? a+b+(c+a)*(a + b*(c+a)) : a+b+(c+a)*(a + b*(c+a)); // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1146 void test_signed_nested_expr_negative() {
1150 a = a > 5 ? a+b+(c+a)*(a + b*(c+a)) : a+b+(c+a)*(a + b*(a+c)); // no warning
1153 void test_signed_nested_cond_expr_negative() {
1157 a = a > 5 ? (b > 5 ? 1 : 4) : (b > 5 ? 2 : 4); // no warning
1160 void test_signed_nested_cond_expr() {
1164 a = a > 5 ? (b > 5 ? 1 : 4) : (b > 5 ? 4 : 4); // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1167 void test_identical_branches1(bool b) {
1169 if (b) { // expected-warning {{true and false branches are identical}}
1176 void test_identical_branches2(bool b) {
1178 if (b) { // expected-warning {{true and false branches are identical}}
1184 void test_identical_branches3(bool b) {
1186 if (b) { // no warning
1193 void test_identical_branches4(bool b) {
1195 if (b) { // expected-warning {{true and false branches are identical}}
1200 void test_identical_branches_break(bool b) {
1202 if (b) // expected-warning {{true and false branches are identical}}
1209 void test_identical_branches_continue(bool b) {
1211 if (b) // expected-warning {{true and false branches are identical}}
1218 void test_identical_branches_func(bool b) {
1219 if (b) // expected-warning {{true and false branches are identical}}
1225 void test_identical_branches_func_arguments(bool b) {
1226 if (b) // no-warning
1232 void test_identical_branches_cast1(bool b) {
1234 if (b) // no-warning
1237 v = (unsigned int) v;
1240 void test_identical_branches_cast2(bool b) {
1242 if (b) // expected-warning {{true and false branches are identical}}
1248 int test_identical_branches_return_int(bool b) {
1250 if (b) { // expected-warning {{true and false branches are identical}}
1259 int test_identical_branches_return_func(bool b) {
1260 if (b) { // expected-warning {{true and false branches are identical}}
1267 void test_identical_branches_for(bool b) {
1270 if (b) { // expected-warning {{true and false branches are identical}}
1271 for (i = 0, j = 0; i < 10; i++)
1274 for (i = 0, j = 0; i < 10; i++)
1279 void test_identical_branches_while(bool b) {
1281 if (b) { // expected-warning {{true and false branches are identical}}
1290 void test_identical_branches_while_2(bool b) {
1292 if (b) { // no-warning
1301 void test_identical_branches_do_while(bool b) {
1303 if (b) { // expected-warning {{true and false branches are identical}}
1314 void test_identical_branches_if(bool b, int i) {
1315 if (b) { // expected-warning {{true and false branches are identical}}
1324 void test_identical_bitwise1() {
1325 int a = 5 | 5; // expected-warning {{identical expressions on both sides of bitwise operator}}
1328 void test_identical_bitwise2() {
1330 int b = a | a; // expected-warning {{identical expressions on both sides of bitwise operator}}
1333 void test_identical_bitwise3() {
1335 int b = (a | a); // expected-warning {{identical expressions on both sides of bitwise operator}}
1338 void test_identical_bitwise4() {
1340 int b = a | 4; // no-warning
1343 void test_identical_bitwise5() {
1346 int c = a | b; // no-warning
1349 void test_identical_bitwise6() {
1351 int b = a | 4 | a; // expected-warning {{identical expressions on both sides of bitwise operator}}
1354 void test_identical_bitwise7() {
1356 int b = func() | func(); // no-warning
1359 void test_identical_logical1(int a) {
1360 if (a == 4 && a == 4) // expected-warning {{identical expressions on both sides of logical operator}}
1364 void test_identical_logical2(int a) {
1365 if (a == 4 || a == 5 || a == 4) // expected-warning {{identical expressions on both sides of logical operator}}
1369 void test_identical_logical3(int a) {
1370 if (a == 4 || a == 5 || a == 6) // no-warning
1374 void test_identical_logical4(int a) {
1375 if (a == func() || a == func()) // no-warning
1379 #pragma clang diagnostic push
1380 #pragma clang diagnostic ignored "-Wlogical-op-parentheses"
1381 void test_identical_logical5(int x, int y) {
1382 if (x == 4 && y == 5 || x == 4 && y == 6) // no-warning
1386 void test_identical_logical6(int x, int y) {
1387 if (x == 4 && y == 5 || x == 4 && y == 5) // expected-warning {{identical expressions on both sides of logical operator}}
1391 void test_identical_logical7(int x, int y) {
1392 // FIXME: We should warn here
1393 if (x == 4 && y == 5 || x == 4)
1397 void test_identical_logical8(int x, int y) {
1398 // FIXME: We should warn here
1399 if (x == 4 || y == 5 && x == 4)
1403 void test_identical_logical9(int x, int y) {
1404 // FIXME: We should warn here
1405 if (x == 4 || x == 4 && y == 5)
1408 #pragma clang diagnostic pop
1410 void test_warn_chained_if_stmts_1(int x) {
1413 else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1417 void test_warn_chained_if_stmts_2(int x) {
1420 else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1422 else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1426 void test_warn_chained_if_stmts_3(int x) {
1431 else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1435 void test_warn_chained_if_stmts_4(int x) {
1440 else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1444 void test_warn_chained_if_stmts_5(int x) {
1447 else if (x & 1) // expected-warning {{expression is identical to previous condition}}
1451 void test_warn_chained_if_stmts_6(int x) {
1456 else if (x == 2) // expected-warning {{expression is identical to previous condition}}
1462 void test_warn_chained_if_stmts_7(int x) {
1469 else if (x == 2) // expected-warning {{expression is identical to previous condition}}
1475 void test_warn_chained_if_stmts_8(int x) {
1482 else if (x == 2) // expected-warning {{expression is identical to previous condition}}
1486 else if (x == 3) // expected-warning {{expression is identical to previous condition}}
1492 void test_nowarn_chained_if_stmts_1(int x) {
1495 else if (func()) // no-warning
1499 void test_nowarn_chained_if_stmts_2(int x) {
1504 else if (func()) // no-warning
1508 void test_nowarn_chained_if_stmts_3(int x) {
1511 else if (x++) // no-warning
1515 void test_warn_wchar() {
1516 const wchar_t * a = 0 ? L"Warning" : L"Warning"; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1518 void test_nowarn_wchar() {
1519 const wchar_t * a = 0 ? L"No" : L"Warning";
1522 void test_nowarn_long() {
1528 } else { // no-warning
1534 // Identical inner conditions
1536 void test_warn_inner_if_1(int x) {
1538 if (x == 1) // expected-warning {{conditions of the inner and outer statements are identical}}
1542 // FIXME: Should warn here. The warning is currently not emitted because there
1543 // is code between the conditions.
1551 void test_nowarn_inner_if_1(int x) {
1552 // Don't warn when condition has side effects.
1558 // Don't warn when x is changed before inner condition.