xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/identical-expressions.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core.IdenticalExpr -w -verify %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc /* Only one expected warning per function allowed at the very end. */
4f4a2713aSLionel Sambuc 
func(void)5*0a6a1f1dSLionel Sambuc int func(void)
6*0a6a1f1dSLionel Sambuc {
7*0a6a1f1dSLionel Sambuc   return 0;
8*0a6a1f1dSLionel Sambuc }
9*0a6a1f1dSLionel Sambuc 
func2(void)10*0a6a1f1dSLionel Sambuc int func2(void)
11*0a6a1f1dSLionel Sambuc {
12*0a6a1f1dSLionel Sambuc   return 0;
13*0a6a1f1dSLionel Sambuc }
14*0a6a1f1dSLionel Sambuc 
funcParam(int a)15*0a6a1f1dSLionel Sambuc int funcParam(int a)
16*0a6a1f1dSLionel Sambuc {
17*0a6a1f1dSLionel Sambuc   return 0;
18*0a6a1f1dSLionel Sambuc }
19*0a6a1f1dSLionel Sambuc 
20f4a2713aSLionel Sambuc /* '!=' operator*/
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc /* '!=' with float */
checkNotEqualFloatLiteralCompare1(void)23f4a2713aSLionel Sambuc int checkNotEqualFloatLiteralCompare1(void) {
24f4a2713aSLionel Sambuc   return (5.14F != 5.14F); // no warning
25f4a2713aSLionel Sambuc }
26f4a2713aSLionel Sambuc 
checkNotEqualFloatLiteralCompare2(void)27f4a2713aSLionel Sambuc int checkNotEqualFloatLiteralCompare2(void) {
28f4a2713aSLionel Sambuc   return (6.14F != 7.14F); // no warning
29f4a2713aSLionel Sambuc }
30f4a2713aSLionel Sambuc 
checkNotEqualFloatDeclCompare1(void)31f4a2713aSLionel Sambuc int checkNotEqualFloatDeclCompare1(void) {
32f4a2713aSLionel Sambuc   float f = 7.1F;
33f4a2713aSLionel Sambuc   float g = 7.1F;
34f4a2713aSLionel Sambuc   return (f != g); // no warning
35f4a2713aSLionel Sambuc }
36f4a2713aSLionel Sambuc 
checkNotEqualFloatDeclCompare12(void)37f4a2713aSLionel Sambuc int checkNotEqualFloatDeclCompare12(void) {
38f4a2713aSLionel Sambuc   float f = 7.1F;
39f4a2713aSLionel Sambuc   return (f != f); // no warning
40f4a2713aSLionel Sambuc }
41f4a2713aSLionel Sambuc 
checkNotEqualFloatDeclCompare3(void)42f4a2713aSLionel Sambuc int checkNotEqualFloatDeclCompare3(void) {
43f4a2713aSLionel Sambuc   float f = 7.1F;
44f4a2713aSLionel Sambuc   return (f != 7.1F); // no warning
45f4a2713aSLionel Sambuc }
46f4a2713aSLionel Sambuc 
checkNotEqualFloatDeclCompare4(void)47f4a2713aSLionel Sambuc int checkNotEqualFloatDeclCompare4(void) {
48f4a2713aSLionel Sambuc   float f = 7.1F;
49f4a2713aSLionel Sambuc   return (7.1F != f); // no warning
50f4a2713aSLionel Sambuc }
51f4a2713aSLionel Sambuc 
checkNotEqualFloatDeclCompare5(void)52f4a2713aSLionel Sambuc int checkNotEqualFloatDeclCompare5(void) {
53f4a2713aSLionel Sambuc   float f = 7.1F;
54f4a2713aSLionel Sambuc   int t = 7;
55f4a2713aSLionel Sambuc   return (t != f); // no warning
56f4a2713aSLionel Sambuc }
57f4a2713aSLionel Sambuc 
checkNotEqualFloatDeclCompare6(void)58f4a2713aSLionel Sambuc int checkNotEqualFloatDeclCompare6(void) {
59f4a2713aSLionel Sambuc   float f = 7.1F;
60f4a2713aSLionel Sambuc   int t = 7;
61f4a2713aSLionel Sambuc   return (f != t); // no warning
62f4a2713aSLionel Sambuc }
63f4a2713aSLionel Sambuc 
64f4a2713aSLionel Sambuc 
65f4a2713aSLionel Sambuc 
checkNotEqualCastFloatDeclCompare11(void)66f4a2713aSLionel Sambuc int checkNotEqualCastFloatDeclCompare11(void) {
67f4a2713aSLionel Sambuc   float f = 7.1F;
68f4a2713aSLionel Sambuc   return ((int)f != (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
69f4a2713aSLionel Sambuc }
checkNotEqualCastFloatDeclCompare12(void)70f4a2713aSLionel Sambuc int checkNotEqualCastFloatDeclCompare12(void) {
71f4a2713aSLionel Sambuc   float f = 7.1F;
72f4a2713aSLionel Sambuc   return ((char)f != (int)f); // no warning
73f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpFloatCompare1(void)74f4a2713aSLionel Sambuc int checkNotEqualBinaryOpFloatCompare1(void) {
75f4a2713aSLionel Sambuc   int res;
76f4a2713aSLionel Sambuc   float f= 3.14F;
77f4a2713aSLionel Sambuc   res = (f + 3.14F != f + 3.14F);  // no warning
78f4a2713aSLionel Sambuc   return (0);
79f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpFloatCompare2(void)80f4a2713aSLionel Sambuc int checkNotEqualBinaryOpFloatCompare2(void) {
81f4a2713aSLionel Sambuc   float f = 7.1F;
82f4a2713aSLionel Sambuc   float g = 7.1F;
83f4a2713aSLionel Sambuc   return (f + 3.14F != g + 3.14F); // no warning
84f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpFloatCompare3(void)85f4a2713aSLionel Sambuc int checkNotEqualBinaryOpFloatCompare3(void) {
86f4a2713aSLionel Sambuc   int res;
87f4a2713aSLionel Sambuc   float f= 3.14F;
88f4a2713aSLionel Sambuc   res = ((int)f + 3.14F != (int)f + 3.14F);  // no warning
89f4a2713aSLionel Sambuc   return (0);
90f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpFloatCompare4(void)91f4a2713aSLionel Sambuc int checkNotEqualBinaryOpFloatCompare4(void) {
92f4a2713aSLionel Sambuc   int res;
93f4a2713aSLionel Sambuc   float f= 3.14F;
94f4a2713aSLionel Sambuc   res = ((int)f + 3.14F != (char)f + 3.14F);  // no warning
95f4a2713aSLionel Sambuc   return (0);
96f4a2713aSLionel Sambuc }
97f4a2713aSLionel Sambuc 
checkNotEqualNestedBinaryOpFloatCompare1(void)98f4a2713aSLionel Sambuc int checkNotEqualNestedBinaryOpFloatCompare1(void) {
99f4a2713aSLionel Sambuc   int res;
100f4a2713aSLionel Sambuc   int t= 1;
101f4a2713aSLionel Sambuc   int u= 2;
102f4a2713aSLionel Sambuc   float f= 3.14F;
103f4a2713aSLionel Sambuc   res = (((int)f + (3.14F - u)*t) != ((int)f + (3.14F - u)*t));  // no warning
104f4a2713aSLionel Sambuc   return (0);
105f4a2713aSLionel Sambuc }
106f4a2713aSLionel Sambuc 
checkNotEqualNestedBinaryOpFloatCompare2(void)107f4a2713aSLionel Sambuc int checkNotEqualNestedBinaryOpFloatCompare2(void) {
108f4a2713aSLionel Sambuc   int res;
109f4a2713aSLionel Sambuc   int t= 1;
110f4a2713aSLionel Sambuc   int u= 2;
111f4a2713aSLionel Sambuc   float f= 3.14F;
112f4a2713aSLionel Sambuc   res = (((int)f + (u - 3.14F)*t) != ((int)f + (3.14F - u)*t));  // no warning
113f4a2713aSLionel Sambuc   return (0);
114f4a2713aSLionel Sambuc }
115f4a2713aSLionel Sambuc 
checkNotEqualNestedBinaryOpFloatCompare3(void)116f4a2713aSLionel Sambuc int checkNotEqualNestedBinaryOpFloatCompare3(void) {
117f4a2713aSLionel Sambuc   int res;
118f4a2713aSLionel Sambuc   int t= 1;
119f4a2713aSLionel Sambuc   int u= 2;
120f4a2713aSLionel Sambuc   float f= 3.14F;
121f4a2713aSLionel Sambuc   res = (((int)f + (u - 3.14F)*t) != ((int)f + (3.14F - u)*(f + t != f + t)));  // no warning
122f4a2713aSLionel Sambuc   return (0);
123f4a2713aSLionel Sambuc }
124f4a2713aSLionel Sambuc 
125f4a2713aSLionel Sambuc 
126f4a2713aSLionel Sambuc 
127f4a2713aSLionel Sambuc 
128f4a2713aSLionel Sambuc /* end '!=' with float*/
129f4a2713aSLionel Sambuc 
130f4a2713aSLionel Sambuc /* '!=' with int*/
131f4a2713aSLionel Sambuc 
checkNotEqualIntLiteralCompare1(void)132f4a2713aSLionel Sambuc int checkNotEqualIntLiteralCompare1(void) {
133f4a2713aSLionel Sambuc   return (5 != 5); // expected-warning {{comparison of identical expressions always evaluates to false}}
134f4a2713aSLionel Sambuc }
135f4a2713aSLionel Sambuc 
checkNotEqualIntLiteralCompare2(void)136f4a2713aSLionel Sambuc int checkNotEqualIntLiteralCompare2(void) {
137f4a2713aSLionel Sambuc   return (6 != 7); // no warning
138f4a2713aSLionel Sambuc }
139f4a2713aSLionel Sambuc 
checkNotEqualIntDeclCompare1(void)140f4a2713aSLionel Sambuc int checkNotEqualIntDeclCompare1(void) {
141f4a2713aSLionel Sambuc   int f = 7;
142f4a2713aSLionel Sambuc   int g = 7;
143f4a2713aSLionel Sambuc   return (f != g); // no warning
144f4a2713aSLionel Sambuc }
145f4a2713aSLionel Sambuc 
checkNotEqualIntDeclCompare3(void)146f4a2713aSLionel Sambuc int checkNotEqualIntDeclCompare3(void) {
147f4a2713aSLionel Sambuc   int f = 7;
148f4a2713aSLionel Sambuc   return (f != 7); // no warning
149f4a2713aSLionel Sambuc }
150f4a2713aSLionel Sambuc 
checkNotEqualIntDeclCompare4(void)151f4a2713aSLionel Sambuc int checkNotEqualIntDeclCompare4(void) {
152f4a2713aSLionel Sambuc   int f = 7;
153f4a2713aSLionel Sambuc   return (7 != f); // no warning
154f4a2713aSLionel Sambuc }
155f4a2713aSLionel Sambuc 
checkNotEqualCastIntDeclCompare11(void)156f4a2713aSLionel Sambuc int checkNotEqualCastIntDeclCompare11(void) {
157f4a2713aSLionel Sambuc   int f = 7;
158f4a2713aSLionel Sambuc   return ((int)f != (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
159f4a2713aSLionel Sambuc }
checkNotEqualCastIntDeclCompare12(void)160f4a2713aSLionel Sambuc int checkNotEqualCastIntDeclCompare12(void) {
161f4a2713aSLionel Sambuc   int f = 7;
162f4a2713aSLionel Sambuc   return ((char)f != (int)f); // no warning
163f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpIntCompare1(void)164f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntCompare1(void) {
165f4a2713aSLionel Sambuc   int res;
166f4a2713aSLionel Sambuc   int t= 1;
167f4a2713aSLionel Sambuc   int u= 2;
168f4a2713aSLionel Sambuc   int f= 4;
169f4a2713aSLionel Sambuc   res = (f + 4 != f + 4);  // expected-warning {{comparison of identical expressions always evaluates to false}}
170f4a2713aSLionel Sambuc   return (0);
171f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpIntCompare2(void)172f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntCompare2(void) {
173f4a2713aSLionel Sambuc   int f = 7;
174f4a2713aSLionel Sambuc   int g = 7;
175f4a2713aSLionel Sambuc   return (f + 4 != g + 4); // no warning
176f4a2713aSLionel Sambuc }
177f4a2713aSLionel Sambuc 
178f4a2713aSLionel Sambuc 
checkNotEqualBinaryOpIntCompare3(void)179f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntCompare3(void) {
180f4a2713aSLionel Sambuc   int res;
181f4a2713aSLionel Sambuc   int t= 1;
182f4a2713aSLionel Sambuc   int u= 2;
183f4a2713aSLionel Sambuc   int f= 4;
184f4a2713aSLionel Sambuc   res = ((int)f + 4 != (int)f + 4);  // expected-warning {{comparison of identical expressions always evaluates to false}}
185f4a2713aSLionel Sambuc   return (0);
186f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpIntCompare4(void)187f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntCompare4(void) {
188f4a2713aSLionel Sambuc   int res;
189f4a2713aSLionel Sambuc   int t= 1;
190f4a2713aSLionel Sambuc   int u= 2;
191f4a2713aSLionel Sambuc   int f= 4;
192f4a2713aSLionel Sambuc   res = ((int)f + 4 != (char)f + 4);  // no warning
193f4a2713aSLionel Sambuc   return (0);
194f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpIntCompare5(void)195f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntCompare5(void) {
196f4a2713aSLionel Sambuc   int res;
197f4a2713aSLionel Sambuc   int t= 1;
198f4a2713aSLionel Sambuc   int u= 2;
199f4a2713aSLionel Sambuc   res = (u + t != u + t);  // expected-warning {{comparison of identical expressions always evaluates to false}}
200f4a2713aSLionel Sambuc   return (0);
201f4a2713aSLionel Sambuc }
202f4a2713aSLionel Sambuc 
checkNotEqualNestedBinaryOpIntCompare1(void)203f4a2713aSLionel Sambuc int checkNotEqualNestedBinaryOpIntCompare1(void) {
204f4a2713aSLionel Sambuc   int res;
205f4a2713aSLionel Sambuc   int t= 1;
206f4a2713aSLionel Sambuc   int u= 2;
207f4a2713aSLionel Sambuc   int f= 3;
208f4a2713aSLionel Sambuc   res = (((int)f + (3 - u)*t) != ((int)f + (3 - u)*t));  // expected-warning {{comparison of identical expressions always evaluates to false}}
209f4a2713aSLionel Sambuc   return (0);
210f4a2713aSLionel Sambuc }
211f4a2713aSLionel Sambuc 
checkNotEqualNestedBinaryOpIntCompare2(void)212f4a2713aSLionel Sambuc int checkNotEqualNestedBinaryOpIntCompare2(void) {
213f4a2713aSLionel Sambuc   int res;
214f4a2713aSLionel Sambuc   int t= 1;
215f4a2713aSLionel Sambuc   int u= 2;
216f4a2713aSLionel Sambuc   int f= 3;
217f4a2713aSLionel Sambuc   res = (((int)f + (u - 3)*t) != ((int)f + (3 - u)*t));  // no warning
218f4a2713aSLionel Sambuc   return (0);
219f4a2713aSLionel Sambuc }
220f4a2713aSLionel Sambuc 
checkNotEqualNestedBinaryOpIntCompare3(void)221f4a2713aSLionel Sambuc int checkNotEqualNestedBinaryOpIntCompare3(void) {
222f4a2713aSLionel Sambuc   int res;
223f4a2713aSLionel Sambuc   int t= 1;
224f4a2713aSLionel Sambuc   int u= 2;
225f4a2713aSLionel Sambuc   int f= 3;
226f4a2713aSLionel Sambuc   res = (((int)f + (u - 3)*t) != ((int)f + (3 - u)*(t + 1 != t + 1)));  // expected-warning {{comparison of identical expressions always evaluates to false}}
227f4a2713aSLionel Sambuc   return (0);
228f4a2713aSLionel Sambuc }
229f4a2713aSLionel Sambuc 
230f4a2713aSLionel Sambuc /*   end '!=' int          */
231f4a2713aSLionel Sambuc 
232f4a2713aSLionel Sambuc 
233f4a2713aSLionel Sambuc 
234f4a2713aSLionel Sambuc /* '!=' with int pointer */
235f4a2713aSLionel Sambuc 
checkNotEqualIntPointerLiteralCompare1(void)236f4a2713aSLionel Sambuc int checkNotEqualIntPointerLiteralCompare1(void) {
237f4a2713aSLionel Sambuc   int* p = 0;
238f4a2713aSLionel Sambuc   return (p != 0); // no warning
239f4a2713aSLionel Sambuc }
240f4a2713aSLionel Sambuc 
checkNotEqualIntPointerLiteralCompare2(void)241f4a2713aSLionel Sambuc int checkNotEqualIntPointerLiteralCompare2(void) {
242f4a2713aSLionel Sambuc   return (6 != 7); // no warning
243f4a2713aSLionel Sambuc }
244f4a2713aSLionel Sambuc 
checkNotEqualIntPointerDeclCompare1(void)245f4a2713aSLionel Sambuc int checkNotEqualIntPointerDeclCompare1(void) {
246f4a2713aSLionel Sambuc   int k = 3;
247f4a2713aSLionel Sambuc   int* f = &k;
248f4a2713aSLionel Sambuc   int* g = &k;
249f4a2713aSLionel Sambuc   return (f != g); // no warning
250f4a2713aSLionel Sambuc }
251f4a2713aSLionel Sambuc 
checkNotEqualCastIntPointerDeclCompare11(void)252f4a2713aSLionel Sambuc int checkNotEqualCastIntPointerDeclCompare11(void) {
253f4a2713aSLionel Sambuc   int k = 7;
254f4a2713aSLionel Sambuc   int* f = &k;
255f4a2713aSLionel Sambuc   return ((int*)f != (int*)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
256f4a2713aSLionel Sambuc }
checkNotEqualCastIntPointerDeclCompare12(void)257f4a2713aSLionel Sambuc int checkNotEqualCastIntPointerDeclCompare12(void) {
258f4a2713aSLionel Sambuc   int k = 7;
259f4a2713aSLionel Sambuc   int* f = &k;
260f4a2713aSLionel Sambuc   return ((int*)((char*)f) != (int*)f); // no warning
261f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpIntPointerCompare1(void)262f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntPointerCompare1(void) {
263f4a2713aSLionel Sambuc   int k = 7;
264f4a2713aSLionel Sambuc   int res;
265f4a2713aSLionel Sambuc   int* f= &k;
266f4a2713aSLionel Sambuc   res = (f + 4 != f + 4);  // expected-warning {{comparison of identical expressions always evaluates to false}}
267f4a2713aSLionel Sambuc   return (0);
268f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpIntPointerCompare2(void)269f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntPointerCompare2(void) {
270f4a2713aSLionel Sambuc   int k = 7;
271f4a2713aSLionel Sambuc   int* f = &k;
272f4a2713aSLionel Sambuc   int* g = &k;
273f4a2713aSLionel Sambuc   return (f + 4 != g + 4); // no warning
274f4a2713aSLionel Sambuc }
275f4a2713aSLionel Sambuc 
276f4a2713aSLionel Sambuc 
checkNotEqualBinaryOpIntPointerCompare3(void)277f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntPointerCompare3(void) {
278f4a2713aSLionel Sambuc   int k = 7;
279f4a2713aSLionel Sambuc   int res;
280f4a2713aSLionel Sambuc   int* f= &k;
281f4a2713aSLionel Sambuc   res = ((int*)f + 4 != (int*)f + 4);  // expected-warning {{comparison of identical expressions always evaluates to false}}
282f4a2713aSLionel Sambuc   return (0);
283f4a2713aSLionel Sambuc }
checkNotEqualBinaryOpIntPointerCompare4(void)284f4a2713aSLionel Sambuc int checkNotEqualBinaryOpIntPointerCompare4(void) {
285f4a2713aSLionel Sambuc   int k = 7;
286f4a2713aSLionel Sambuc   int res;
287f4a2713aSLionel Sambuc   int* f= &k;
288f4a2713aSLionel Sambuc   res = ((int*)f + 4 != (int*)((char*)f) + 4);  // no warning
289f4a2713aSLionel Sambuc   return (0);
290f4a2713aSLionel Sambuc }
291f4a2713aSLionel Sambuc 
checkNotEqualNestedBinaryOpIntPointerCompare1(void)292f4a2713aSLionel Sambuc int checkNotEqualNestedBinaryOpIntPointerCompare1(void) {
293f4a2713aSLionel Sambuc   int res;
294f4a2713aSLionel Sambuc   int k = 7;
295f4a2713aSLionel Sambuc   int t= 1;
296f4a2713aSLionel Sambuc   int* u= &k+2;
297f4a2713aSLionel Sambuc   int* f= &k+3;
298f4a2713aSLionel Sambuc   res = ((f + (3)*t) != (f + (3)*t));  // expected-warning {{comparison of identical expressions always evaluates to false}}
299f4a2713aSLionel Sambuc   return (0);
300f4a2713aSLionel Sambuc }
301f4a2713aSLionel Sambuc 
checkNotEqualNestedBinaryOpIntPointerCompare2(void)302f4a2713aSLionel Sambuc int checkNotEqualNestedBinaryOpIntPointerCompare2(void) {
303f4a2713aSLionel Sambuc   int res;
304f4a2713aSLionel Sambuc   int k = 7;
305f4a2713aSLionel Sambuc   int t= 1;
306f4a2713aSLionel Sambuc   int* u= &k+2;
307f4a2713aSLionel Sambuc   int* f= &k+3;
308f4a2713aSLionel Sambuc   res = (((3)*t + f) != (f + (3)*t));  // no warning
309f4a2713aSLionel Sambuc   return (0);
310f4a2713aSLionel Sambuc }
311f4a2713aSLionel Sambuc /*   end '!=' int*          */
312f4a2713aSLionel Sambuc 
313*0a6a1f1dSLionel Sambuc /* '!=' with function*/
314*0a6a1f1dSLionel Sambuc 
checkNotEqualSameFunction()315*0a6a1f1dSLionel Sambuc int checkNotEqualSameFunction() {
316*0a6a1f1dSLionel Sambuc   unsigned a = 0;
317*0a6a1f1dSLionel Sambuc   unsigned b = 1;
318*0a6a1f1dSLionel Sambuc   int res = (a+func() != a+func());  // no warning
319*0a6a1f1dSLionel Sambuc   return (0);
320*0a6a1f1dSLionel Sambuc }
321*0a6a1f1dSLionel Sambuc 
checkNotEqualDifferentFunction()322*0a6a1f1dSLionel Sambuc int checkNotEqualDifferentFunction() {
323*0a6a1f1dSLionel Sambuc   unsigned a = 0;
324*0a6a1f1dSLionel Sambuc   unsigned b = 1;
325*0a6a1f1dSLionel Sambuc   int res = (a+func() != a+func2());  // no warning
326*0a6a1f1dSLionel Sambuc   return (0);
327*0a6a1f1dSLionel Sambuc }
328*0a6a1f1dSLionel Sambuc 
checkNotEqualSameFunctionSameParam()329*0a6a1f1dSLionel Sambuc int checkNotEqualSameFunctionSameParam() {
330*0a6a1f1dSLionel Sambuc   unsigned a = 0;
331*0a6a1f1dSLionel Sambuc   unsigned b = 1;
332*0a6a1f1dSLionel Sambuc   int res = (a+funcParam(a) != a+funcParam(a));  // no warning
333*0a6a1f1dSLionel Sambuc   return (0);
334*0a6a1f1dSLionel Sambuc }
335*0a6a1f1dSLionel Sambuc 
checkNotEqualSameFunctionDifferentParam()336*0a6a1f1dSLionel Sambuc int checkNotEqualSameFunctionDifferentParam() {
337*0a6a1f1dSLionel Sambuc   unsigned a = 0;
338*0a6a1f1dSLionel Sambuc   unsigned b = 1;
339*0a6a1f1dSLionel Sambuc   int res = (a+funcParam(a) != a+funcParam(b));  // no warning
340*0a6a1f1dSLionel Sambuc   return (0);
341*0a6a1f1dSLionel Sambuc }
342*0a6a1f1dSLionel Sambuc 
343*0a6a1f1dSLionel Sambuc /*   end '!=' with function*/
344*0a6a1f1dSLionel Sambuc 
345f4a2713aSLionel Sambuc /*   end '!=' */
346f4a2713aSLionel Sambuc 
347f4a2713aSLionel Sambuc 
348f4a2713aSLionel Sambuc 
349f4a2713aSLionel Sambuc /* EQ operator           */
350f4a2713aSLionel Sambuc 
checkEqualIntPointerDeclCompare(void)351f4a2713aSLionel Sambuc int checkEqualIntPointerDeclCompare(void) {
352f4a2713aSLionel Sambuc   int k = 3;
353f4a2713aSLionel Sambuc   int* f = &k;
354f4a2713aSLionel Sambuc   int* g = &k;
355f4a2713aSLionel Sambuc   return (f == g); // no warning
356f4a2713aSLionel Sambuc }
357f4a2713aSLionel Sambuc 
checkEqualIntPointerDeclCompare0(void)358f4a2713aSLionel Sambuc int checkEqualIntPointerDeclCompare0(void) {
359f4a2713aSLionel Sambuc   int k = 3;
360f4a2713aSLionel Sambuc   int* f = &k;
361f4a2713aSLionel Sambuc   return (f+1 == f+1); // expected-warning {{comparison of identical expressions always evaluates to true}}
362f4a2713aSLionel Sambuc }
363f4a2713aSLionel Sambuc 
364f4a2713aSLionel Sambuc /* EQ with float*/
365f4a2713aSLionel Sambuc 
checkEqualFloatLiteralCompare1(void)366f4a2713aSLionel Sambuc int checkEqualFloatLiteralCompare1(void) {
367f4a2713aSLionel Sambuc   return (5.14F == 5.14F); // no warning
368f4a2713aSLionel Sambuc }
369f4a2713aSLionel Sambuc 
checkEqualFloatLiteralCompare2(void)370f4a2713aSLionel Sambuc int checkEqualFloatLiteralCompare2(void) {
371f4a2713aSLionel Sambuc   return (6.14F == 7.14F); // no warning
372f4a2713aSLionel Sambuc }
373f4a2713aSLionel Sambuc 
checkEqualFloatDeclCompare1(void)374f4a2713aSLionel Sambuc int checkEqualFloatDeclCompare1(void) {
375f4a2713aSLionel Sambuc   float f = 7.1F;
376f4a2713aSLionel Sambuc   float g = 7.1F;
377f4a2713aSLionel Sambuc   return (f == g); // no warning
378f4a2713aSLionel Sambuc }
379f4a2713aSLionel Sambuc 
checkEqualFloatDeclCompare12(void)380f4a2713aSLionel Sambuc int checkEqualFloatDeclCompare12(void) {
381f4a2713aSLionel Sambuc   float f = 7.1F;
382f4a2713aSLionel Sambuc   return (f == f); // no warning
383f4a2713aSLionel Sambuc }
384f4a2713aSLionel Sambuc 
385f4a2713aSLionel Sambuc 
checkEqualFloatDeclCompare3(void)386f4a2713aSLionel Sambuc int checkEqualFloatDeclCompare3(void) {
387f4a2713aSLionel Sambuc   float f = 7.1F;
388f4a2713aSLionel Sambuc   return (f == 7.1F); // no warning
389f4a2713aSLionel Sambuc }
390f4a2713aSLionel Sambuc 
checkEqualFloatDeclCompare4(void)391f4a2713aSLionel Sambuc int checkEqualFloatDeclCompare4(void) {
392f4a2713aSLionel Sambuc   float f = 7.1F;
393f4a2713aSLionel Sambuc   return (7.1F == f); // no warning
394f4a2713aSLionel Sambuc }
395f4a2713aSLionel Sambuc 
checkEqualFloatDeclCompare5(void)396f4a2713aSLionel Sambuc int checkEqualFloatDeclCompare5(void) {
397f4a2713aSLionel Sambuc   float f = 7.1F;
398f4a2713aSLionel Sambuc   int t = 7;
399f4a2713aSLionel Sambuc   return (t == f); // no warning
400f4a2713aSLionel Sambuc }
401f4a2713aSLionel Sambuc 
checkEqualFloatDeclCompare6(void)402f4a2713aSLionel Sambuc int checkEqualFloatDeclCompare6(void) {
403f4a2713aSLionel Sambuc   float f = 7.1F;
404f4a2713aSLionel Sambuc   int t = 7;
405f4a2713aSLionel Sambuc   return (f == t); // no warning
406f4a2713aSLionel Sambuc }
407f4a2713aSLionel Sambuc 
408f4a2713aSLionel Sambuc 
409f4a2713aSLionel Sambuc 
410f4a2713aSLionel Sambuc 
checkEqualCastFloatDeclCompare11(void)411f4a2713aSLionel Sambuc int checkEqualCastFloatDeclCompare11(void) {
412f4a2713aSLionel Sambuc   float f = 7.1F;
413f4a2713aSLionel Sambuc   return ((int)f == (int)f); // expected-warning {{comparison of identical expressions always evaluates to true}}
414f4a2713aSLionel Sambuc }
checkEqualCastFloatDeclCompare12(void)415f4a2713aSLionel Sambuc int checkEqualCastFloatDeclCompare12(void) {
416f4a2713aSLionel Sambuc   float f = 7.1F;
417f4a2713aSLionel Sambuc   return ((char)f == (int)f); // no warning
418f4a2713aSLionel Sambuc }
checkEqualBinaryOpFloatCompare1(void)419f4a2713aSLionel Sambuc int checkEqualBinaryOpFloatCompare1(void) {
420f4a2713aSLionel Sambuc   int res;
421f4a2713aSLionel Sambuc   float f= 3.14F;
422f4a2713aSLionel Sambuc   res = (f + 3.14F == f + 3.14F);  // no warning
423f4a2713aSLionel Sambuc   return (0);
424f4a2713aSLionel Sambuc }
checkEqualBinaryOpFloatCompare2(void)425f4a2713aSLionel Sambuc int checkEqualBinaryOpFloatCompare2(void) {
426f4a2713aSLionel Sambuc   float f = 7.1F;
427f4a2713aSLionel Sambuc   float g = 7.1F;
428f4a2713aSLionel Sambuc   return (f + 3.14F == g + 3.14F); // no warning
429f4a2713aSLionel Sambuc }
checkEqualBinaryOpFloatCompare3(void)430f4a2713aSLionel Sambuc int checkEqualBinaryOpFloatCompare3(void) {
431f4a2713aSLionel Sambuc   int res;
432f4a2713aSLionel Sambuc   float f= 3.14F;
433f4a2713aSLionel Sambuc   res = ((int)f + 3.14F == (int)f + 3.14F);  // no warning
434f4a2713aSLionel Sambuc   return (0);
435f4a2713aSLionel Sambuc }
checkEqualBinaryOpFloatCompare4(void)436f4a2713aSLionel Sambuc int checkEqualBinaryOpFloatCompare4(void) {
437f4a2713aSLionel Sambuc   int res;
438f4a2713aSLionel Sambuc   float f= 3.14F;
439f4a2713aSLionel Sambuc   res = ((int)f + 3.14F == (char)f + 3.14F);  // no warning
440f4a2713aSLionel Sambuc   return (0);
441f4a2713aSLionel Sambuc }
442f4a2713aSLionel Sambuc 
checkEqualNestedBinaryOpFloatCompare1(void)443f4a2713aSLionel Sambuc int checkEqualNestedBinaryOpFloatCompare1(void) {
444f4a2713aSLionel Sambuc   int res;
445f4a2713aSLionel Sambuc   int t= 1;
446f4a2713aSLionel Sambuc   int u= 2;
447f4a2713aSLionel Sambuc   float f= 3.14F;
448f4a2713aSLionel Sambuc   res = (((int)f + (3.14F - u)*t) == ((int)f + (3.14F - u)*t));  // no warning
449f4a2713aSLionel Sambuc   return (0);
450f4a2713aSLionel Sambuc }
451f4a2713aSLionel Sambuc 
checkEqualNestedBinaryOpFloatCompare2(void)452f4a2713aSLionel Sambuc int checkEqualNestedBinaryOpFloatCompare2(void) {
453f4a2713aSLionel Sambuc   int res;
454f4a2713aSLionel Sambuc   int t= 1;
455f4a2713aSLionel Sambuc   int u= 2;
456f4a2713aSLionel Sambuc   float f= 3.14F;
457f4a2713aSLionel Sambuc   res = (((int)f + (u - 3.14F)*t) == ((int)f + (3.14F - u)*t));  // no warning
458f4a2713aSLionel Sambuc   return (0);
459f4a2713aSLionel Sambuc }
460f4a2713aSLionel Sambuc 
checkEqualNestedBinaryOpFloatCompare3(void)461f4a2713aSLionel Sambuc int checkEqualNestedBinaryOpFloatCompare3(void) {
462f4a2713aSLionel Sambuc   int res;
463f4a2713aSLionel Sambuc   int t= 1;
464f4a2713aSLionel Sambuc   int u= 2;
465f4a2713aSLionel Sambuc   float f= 3.14F;
466f4a2713aSLionel Sambuc   res = (((int)f + (u - 3.14F)*t) == ((int)f + (3.14F - u)*(f + t == f + t)));  // no warning
467f4a2713aSLionel Sambuc   return (0);
468f4a2713aSLionel Sambuc }
469f4a2713aSLionel Sambuc 
470f4a2713aSLionel Sambuc 
471f4a2713aSLionel Sambuc 
472f4a2713aSLionel Sambuc 
473f4a2713aSLionel Sambuc 
474f4a2713aSLionel Sambuc /* Equal with int*/
475f4a2713aSLionel Sambuc 
checkEqualIntLiteralCompare1(void)476f4a2713aSLionel Sambuc int checkEqualIntLiteralCompare1(void) {
477f4a2713aSLionel Sambuc   return (5 == 5); // expected-warning {{comparison of identical expressions always evaluates to true}}
478f4a2713aSLionel Sambuc }
479f4a2713aSLionel Sambuc 
checkEqualIntLiteralCompare2(void)480f4a2713aSLionel Sambuc int checkEqualIntLiteralCompare2(void) {
481f4a2713aSLionel Sambuc   return (6 == 7); // no warning
482f4a2713aSLionel Sambuc }
483f4a2713aSLionel Sambuc 
checkEqualIntDeclCompare1(void)484f4a2713aSLionel Sambuc int checkEqualIntDeclCompare1(void) {
485f4a2713aSLionel Sambuc   int f = 7;
486f4a2713aSLionel Sambuc   int g = 7;
487f4a2713aSLionel Sambuc   return (f == g); // no warning
488f4a2713aSLionel Sambuc }
489f4a2713aSLionel Sambuc 
checkEqualCastIntDeclCompare11(void)490f4a2713aSLionel Sambuc int checkEqualCastIntDeclCompare11(void) {
491f4a2713aSLionel Sambuc   int f = 7;
492f4a2713aSLionel Sambuc   return ((int)f == (int)f); // expected-warning {{comparison of identical expressions always evaluates to true}}
493f4a2713aSLionel Sambuc }
checkEqualCastIntDeclCompare12(void)494f4a2713aSLionel Sambuc int checkEqualCastIntDeclCompare12(void) {
495f4a2713aSLionel Sambuc   int f = 7;
496f4a2713aSLionel Sambuc   return ((char)f == (int)f); // no warning
497f4a2713aSLionel Sambuc }
498f4a2713aSLionel Sambuc 
checkEqualIntDeclCompare3(void)499f4a2713aSLionel Sambuc int checkEqualIntDeclCompare3(void) {
500f4a2713aSLionel Sambuc   int f = 7;
501f4a2713aSLionel Sambuc   return (f == 7); // no warning
502f4a2713aSLionel Sambuc }
503f4a2713aSLionel Sambuc 
checkEqualIntDeclCompare4(void)504f4a2713aSLionel Sambuc int checkEqualIntDeclCompare4(void) {
505f4a2713aSLionel Sambuc   int f = 7;
506f4a2713aSLionel Sambuc   return (7 == f); // no warning
507f4a2713aSLionel Sambuc }
508f4a2713aSLionel Sambuc 
checkEqualBinaryOpIntCompare1(void)509f4a2713aSLionel Sambuc int checkEqualBinaryOpIntCompare1(void) {
510f4a2713aSLionel Sambuc   int res;
511f4a2713aSLionel Sambuc   int t= 1;
512f4a2713aSLionel Sambuc   int u= 2;
513f4a2713aSLionel Sambuc   int f= 4;
514f4a2713aSLionel Sambuc   res = (f + 4 == f + 4);  // expected-warning {{comparison of identical expressions always evaluates to true}}
515f4a2713aSLionel Sambuc   return (0);
516f4a2713aSLionel Sambuc }
checkEqualBinaryOpIntCompare2(void)517f4a2713aSLionel Sambuc int checkEqualBinaryOpIntCompare2(void) {
518f4a2713aSLionel Sambuc   int f = 7;
519f4a2713aSLionel Sambuc   int g = 7;
520f4a2713aSLionel Sambuc   return (f + 4 == g + 4); // no warning
521f4a2713aSLionel Sambuc }
522f4a2713aSLionel Sambuc 
523f4a2713aSLionel Sambuc 
checkEqualBinaryOpIntCompare3(void)524f4a2713aSLionel Sambuc int checkEqualBinaryOpIntCompare3(void) {
525f4a2713aSLionel Sambuc   int res;
526f4a2713aSLionel Sambuc   int t= 1;
527f4a2713aSLionel Sambuc   int u= 2;
528f4a2713aSLionel Sambuc   int f= 4;
529f4a2713aSLionel Sambuc   res = ((int)f + 4 == (int)f + 4);  // expected-warning {{comparison of identical expressions always evaluates to true}}
530f4a2713aSLionel Sambuc   return (0);
531f4a2713aSLionel Sambuc 
532f4a2713aSLionel Sambuc }
checkEqualBinaryOpIntCompare4(void)533f4a2713aSLionel Sambuc int checkEqualBinaryOpIntCompare4(void) {
534f4a2713aSLionel Sambuc   int res;
535f4a2713aSLionel Sambuc   int t= 1;
536f4a2713aSLionel Sambuc   int u= 2;
537f4a2713aSLionel Sambuc   int f= 4;
538f4a2713aSLionel Sambuc   res = ((int)f + 4 == (char)f + 4);  // no warning
539f4a2713aSLionel Sambuc   return (0);
540f4a2713aSLionel Sambuc }
checkEqualBinaryOpIntCompare5(void)541f4a2713aSLionel Sambuc int checkEqualBinaryOpIntCompare5(void) {
542f4a2713aSLionel Sambuc   int res;
543f4a2713aSLionel Sambuc   int t= 1;
544f4a2713aSLionel Sambuc   int u= 2;
545f4a2713aSLionel Sambuc   res = (u + t == u + t);  // expected-warning {{comparison of identical expressions always evaluates to true}}
546f4a2713aSLionel Sambuc   return (0);
547f4a2713aSLionel Sambuc }
548f4a2713aSLionel Sambuc 
checkEqualNestedBinaryOpIntCompare1(void)549f4a2713aSLionel Sambuc int checkEqualNestedBinaryOpIntCompare1(void) {
550f4a2713aSLionel Sambuc   int res;
551f4a2713aSLionel Sambuc   int t= 1;
552f4a2713aSLionel Sambuc   int u= 2;
553f4a2713aSLionel Sambuc   int f= 3;
554f4a2713aSLionel Sambuc   res = (((int)f + (3 - u)*t) == ((int)f + (3 - u)*t));  // expected-warning {{comparison of identical expressions always evaluates to true}}
555f4a2713aSLionel Sambuc   return (0);
556f4a2713aSLionel Sambuc }
557f4a2713aSLionel Sambuc 
checkEqualNestedBinaryOpIntCompare2(void)558f4a2713aSLionel Sambuc int checkEqualNestedBinaryOpIntCompare2(void) {
559f4a2713aSLionel Sambuc   int res;
560f4a2713aSLionel Sambuc   int t= 1;
561f4a2713aSLionel Sambuc   int u= 2;
562f4a2713aSLionel Sambuc   int f= 3;
563f4a2713aSLionel Sambuc   res = (((int)f + (u - 3)*t) == ((int)f + (3 - u)*t));  // no warning
564f4a2713aSLionel Sambuc   return (0);
565f4a2713aSLionel Sambuc }
566f4a2713aSLionel Sambuc 
checkEqualNestedBinaryOpIntCompare3(void)567f4a2713aSLionel Sambuc int checkEqualNestedBinaryOpIntCompare3(void) {
568f4a2713aSLionel Sambuc   int res;
569f4a2713aSLionel Sambuc   int t= 1;
570f4a2713aSLionel Sambuc   int u= 2;
571f4a2713aSLionel Sambuc   int f= 3;
572f4a2713aSLionel Sambuc   res = (((int)f + (u - 3)*t) == ((int)f + (3 - u)*(t + 1 == t + 1)));  // expected-warning {{comparison of identical expressions always evaluates to true}}
573f4a2713aSLionel Sambuc   return (0);
574f4a2713aSLionel Sambuc }
575f4a2713aSLionel Sambuc 
576*0a6a1f1dSLionel Sambuc /* '==' with function*/
577*0a6a1f1dSLionel Sambuc 
checkEqualSameFunction()578*0a6a1f1dSLionel Sambuc int checkEqualSameFunction() {
579*0a6a1f1dSLionel Sambuc   unsigned a = 0;
580*0a6a1f1dSLionel Sambuc   unsigned b = 1;
581*0a6a1f1dSLionel Sambuc   int res = (a+func() == a+func());  // no warning
582*0a6a1f1dSLionel Sambuc   return (0);
583*0a6a1f1dSLionel Sambuc }
584*0a6a1f1dSLionel Sambuc 
checkEqualDifferentFunction()585*0a6a1f1dSLionel Sambuc int checkEqualDifferentFunction() {
586*0a6a1f1dSLionel Sambuc   unsigned a = 0;
587*0a6a1f1dSLionel Sambuc   unsigned b = 1;
588*0a6a1f1dSLionel Sambuc   int res = (a+func() == a+func2());  // no warning
589*0a6a1f1dSLionel Sambuc   return (0);
590*0a6a1f1dSLionel Sambuc }
591*0a6a1f1dSLionel Sambuc 
checkEqualSameFunctionSameParam()592*0a6a1f1dSLionel Sambuc int checkEqualSameFunctionSameParam() {
593*0a6a1f1dSLionel Sambuc   unsigned a = 0;
594*0a6a1f1dSLionel Sambuc   unsigned b = 1;
595*0a6a1f1dSLionel Sambuc   int res = (a+funcParam(a) == a+funcParam(a));  // no warning
596*0a6a1f1dSLionel Sambuc   return (0);
597*0a6a1f1dSLionel Sambuc }
598*0a6a1f1dSLionel Sambuc 
checkEqualSameFunctionDifferentParam()599*0a6a1f1dSLionel Sambuc int checkEqualSameFunctionDifferentParam() {
600*0a6a1f1dSLionel Sambuc   unsigned a = 0;
601*0a6a1f1dSLionel Sambuc   unsigned b = 1;
602*0a6a1f1dSLionel Sambuc   int res = (a+funcParam(a) == a+funcParam(b));  // no warning
603*0a6a1f1dSLionel Sambuc   return (0);
604*0a6a1f1dSLionel Sambuc }
605*0a6a1f1dSLionel Sambuc 
606*0a6a1f1dSLionel Sambuc /*   end '==' with function*/
607f4a2713aSLionel Sambuc 
608f4a2713aSLionel Sambuc /*   end EQ int          */
609f4a2713aSLionel Sambuc 
610f4a2713aSLionel Sambuc /* end EQ */
611f4a2713aSLionel Sambuc 
612f4a2713aSLionel Sambuc 
613f4a2713aSLionel Sambuc /*  LT */
614f4a2713aSLionel Sambuc 
615f4a2713aSLionel Sambuc /*  LT with float */
616f4a2713aSLionel Sambuc 
checkLessThanFloatLiteralCompare1(void)617f4a2713aSLionel Sambuc int checkLessThanFloatLiteralCompare1(void) {
618f4a2713aSLionel Sambuc   return (5.14F < 5.14F); // expected-warning {{comparison of identical expressions always evaluates to false}}
619f4a2713aSLionel Sambuc }
620f4a2713aSLionel Sambuc 
checkLessThanFloatLiteralCompare2(void)621f4a2713aSLionel Sambuc int checkLessThanFloatLiteralCompare2(void) {
622f4a2713aSLionel Sambuc   return (6.14F < 7.14F); // no warning
623f4a2713aSLionel Sambuc }
624f4a2713aSLionel Sambuc 
checkLessThanFloatDeclCompare1(void)625f4a2713aSLionel Sambuc int checkLessThanFloatDeclCompare1(void) {
626f4a2713aSLionel Sambuc   float f = 7.1F;
627f4a2713aSLionel Sambuc   float g = 7.1F;
628f4a2713aSLionel Sambuc   return (f < g); // no warning
629f4a2713aSLionel Sambuc }
630f4a2713aSLionel Sambuc 
checkLessThanFloatDeclCompare12(void)631f4a2713aSLionel Sambuc int checkLessThanFloatDeclCompare12(void) {
632f4a2713aSLionel Sambuc   float f = 7.1F;
633f4a2713aSLionel Sambuc   return (f < f); // expected-warning {{comparison of identical expressions always evaluates to false}}
634f4a2713aSLionel Sambuc }
635f4a2713aSLionel Sambuc 
checkLessThanFloatDeclCompare3(void)636f4a2713aSLionel Sambuc int checkLessThanFloatDeclCompare3(void) {
637f4a2713aSLionel Sambuc   float f = 7.1F;
638f4a2713aSLionel Sambuc   return (f < 7.1F); // no warning
639f4a2713aSLionel Sambuc }
640f4a2713aSLionel Sambuc 
checkLessThanFloatDeclCompare4(void)641f4a2713aSLionel Sambuc int checkLessThanFloatDeclCompare4(void) {
642f4a2713aSLionel Sambuc   float f = 7.1F;
643f4a2713aSLionel Sambuc   return (7.1F < f); // no warning
644f4a2713aSLionel Sambuc }
645f4a2713aSLionel Sambuc 
checkLessThanFloatDeclCompare5(void)646f4a2713aSLionel Sambuc int checkLessThanFloatDeclCompare5(void) {
647f4a2713aSLionel Sambuc   float f = 7.1F;
648f4a2713aSLionel Sambuc   int t = 7;
649f4a2713aSLionel Sambuc   return (t < f); // no warning
650f4a2713aSLionel Sambuc }
651f4a2713aSLionel Sambuc 
checkLessThanFloatDeclCompare6(void)652f4a2713aSLionel Sambuc int checkLessThanFloatDeclCompare6(void) {
653f4a2713aSLionel Sambuc   float f = 7.1F;
654f4a2713aSLionel Sambuc   int t = 7;
655f4a2713aSLionel Sambuc   return (f < t); // no warning
656f4a2713aSLionel Sambuc }
657f4a2713aSLionel Sambuc 
658f4a2713aSLionel Sambuc 
checkLessThanCastFloatDeclCompare11(void)659f4a2713aSLionel Sambuc int checkLessThanCastFloatDeclCompare11(void) {
660f4a2713aSLionel Sambuc   float f = 7.1F;
661f4a2713aSLionel Sambuc   return ((int)f < (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
662f4a2713aSLionel Sambuc }
checkLessThanCastFloatDeclCompare12(void)663f4a2713aSLionel Sambuc int checkLessThanCastFloatDeclCompare12(void) {
664f4a2713aSLionel Sambuc   float f = 7.1F;
665f4a2713aSLionel Sambuc   return ((char)f < (int)f); // no warning
666f4a2713aSLionel Sambuc }
checkLessThanBinaryOpFloatCompare1(void)667f4a2713aSLionel Sambuc int checkLessThanBinaryOpFloatCompare1(void) {
668f4a2713aSLionel Sambuc   int res;
669f4a2713aSLionel Sambuc   float f= 3.14F;
670f4a2713aSLionel Sambuc   res = (f + 3.14F < f + 3.14F);  // no warning
671f4a2713aSLionel Sambuc   return (0);
672f4a2713aSLionel Sambuc }
checkLessThanBinaryOpFloatCompare2(void)673f4a2713aSLionel Sambuc int checkLessThanBinaryOpFloatCompare2(void) {
674f4a2713aSLionel Sambuc   float f = 7.1F;
675f4a2713aSLionel Sambuc   float g = 7.1F;
676f4a2713aSLionel Sambuc   return (f + 3.14F < g + 3.14F); // no warning
677f4a2713aSLionel Sambuc }
checkLessThanBinaryOpFloatCompare3(void)678f4a2713aSLionel Sambuc int checkLessThanBinaryOpFloatCompare3(void) {
679f4a2713aSLionel Sambuc   int res;
680f4a2713aSLionel Sambuc   float f= 3.14F;
681f4a2713aSLionel Sambuc   res = ((int)f + 3.14F < (int)f + 3.14F);  // no warning
682f4a2713aSLionel Sambuc   return (0);
683f4a2713aSLionel Sambuc }
checkLessThanBinaryOpFloatCompare4(void)684f4a2713aSLionel Sambuc int checkLessThanBinaryOpFloatCompare4(void) {
685f4a2713aSLionel Sambuc   int res;
686f4a2713aSLionel Sambuc   float f= 3.14F;
687f4a2713aSLionel Sambuc   res = ((int)f + 3.14F < (char)f + 3.14F);  // no warning
688f4a2713aSLionel Sambuc   return (0);
689f4a2713aSLionel Sambuc }
690f4a2713aSLionel Sambuc 
checkLessThanNestedBinaryOpFloatCompare1(void)691f4a2713aSLionel Sambuc int checkLessThanNestedBinaryOpFloatCompare1(void) {
692f4a2713aSLionel Sambuc   int res;
693f4a2713aSLionel Sambuc   int t= 1;
694f4a2713aSLionel Sambuc   int u= 2;
695f4a2713aSLionel Sambuc   float f= 3.14F;
696f4a2713aSLionel Sambuc   res = (((int)f + (3.14F - u)*t) < ((int)f + (3.14F - u)*t));  // no warning
697f4a2713aSLionel Sambuc   return (0);
698f4a2713aSLionel Sambuc }
699f4a2713aSLionel Sambuc 
checkLessThanNestedBinaryOpFloatCompare2(void)700f4a2713aSLionel Sambuc int checkLessThanNestedBinaryOpFloatCompare2(void) {
701f4a2713aSLionel Sambuc   int res;
702f4a2713aSLionel Sambuc   int t= 1;
703f4a2713aSLionel Sambuc   int u= 2;
704f4a2713aSLionel Sambuc   float f= 3.14F;
705f4a2713aSLionel Sambuc   res = (((int)f + (u - 3.14F)*t) < ((int)f + (3.14F - u)*t));  // no warning
706f4a2713aSLionel Sambuc   return (0);
707f4a2713aSLionel Sambuc }
708f4a2713aSLionel Sambuc 
checkLessThanNestedBinaryOpFloatCompare3(void)709f4a2713aSLionel Sambuc int checkLessThanNestedBinaryOpFloatCompare3(void) {
710f4a2713aSLionel Sambuc   int res;
711f4a2713aSLionel Sambuc   int t= 1;
712f4a2713aSLionel Sambuc   int u= 2;
713f4a2713aSLionel Sambuc   float f= 3.14F;
714f4a2713aSLionel Sambuc   res = (((int)f + (u - 3.14F)*t) < ((int)f + (3.14F - u)*(f + t < f + t)));  // no warning
715f4a2713aSLionel Sambuc   return (0);
716f4a2713aSLionel Sambuc }
717f4a2713aSLionel Sambuc 
718f4a2713aSLionel Sambuc /*  end LT with float */
719f4a2713aSLionel Sambuc 
720f4a2713aSLionel Sambuc /*  LT with int */
721f4a2713aSLionel Sambuc 
722f4a2713aSLionel Sambuc 
checkLessThanIntLiteralCompare1(void)723f4a2713aSLionel Sambuc int checkLessThanIntLiteralCompare1(void) {
724f4a2713aSLionel Sambuc   return (5 < 5); // expected-warning {{comparison of identical expressions always evaluates to false}}
725f4a2713aSLionel Sambuc }
726f4a2713aSLionel Sambuc 
checkLessThanIntLiteralCompare2(void)727f4a2713aSLionel Sambuc int checkLessThanIntLiteralCompare2(void) {
728f4a2713aSLionel Sambuc   return (6 < 7); // no warning
729f4a2713aSLionel Sambuc }
730f4a2713aSLionel Sambuc 
checkLessThanIntDeclCompare1(void)731f4a2713aSLionel Sambuc int checkLessThanIntDeclCompare1(void) {
732f4a2713aSLionel Sambuc   int f = 7;
733f4a2713aSLionel Sambuc   int g = 7;
734f4a2713aSLionel Sambuc   return (f < g); // no warning
735f4a2713aSLionel Sambuc }
736f4a2713aSLionel Sambuc 
checkLessThanIntDeclCompare3(void)737f4a2713aSLionel Sambuc int checkLessThanIntDeclCompare3(void) {
738f4a2713aSLionel Sambuc   int f = 7;
739f4a2713aSLionel Sambuc   return (f < 7); // no warning
740f4a2713aSLionel Sambuc }
741f4a2713aSLionel Sambuc 
checkLessThanIntDeclCompare4(void)742f4a2713aSLionel Sambuc int checkLessThanIntDeclCompare4(void) {
743f4a2713aSLionel Sambuc   int f = 7;
744f4a2713aSLionel Sambuc   return (7 < f); // no warning
745f4a2713aSLionel Sambuc }
746f4a2713aSLionel Sambuc 
checkLessThanIntDeclCompare5(void)747f4a2713aSLionel Sambuc int checkLessThanIntDeclCompare5(void) {
748f4a2713aSLionel Sambuc   int f = 7;
749f4a2713aSLionel Sambuc   int t = 7;
750f4a2713aSLionel Sambuc   return (t < f); // no warning
751f4a2713aSLionel Sambuc }
752f4a2713aSLionel Sambuc 
checkLessThanIntDeclCompare6(void)753f4a2713aSLionel Sambuc int checkLessThanIntDeclCompare6(void) {
754f4a2713aSLionel Sambuc   int f = 7;
755f4a2713aSLionel Sambuc   int t = 7;
756f4a2713aSLionel Sambuc   return (f < t); // no warning
757f4a2713aSLionel Sambuc }
758f4a2713aSLionel Sambuc 
checkLessThanCastIntDeclCompare11(void)759f4a2713aSLionel Sambuc int checkLessThanCastIntDeclCompare11(void) {
760f4a2713aSLionel Sambuc   int f = 7;
761f4a2713aSLionel Sambuc   return ((int)f < (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
762f4a2713aSLionel Sambuc }
checkLessThanCastIntDeclCompare12(void)763f4a2713aSLionel Sambuc int checkLessThanCastIntDeclCompare12(void) {
764f4a2713aSLionel Sambuc   int f = 7;
765f4a2713aSLionel Sambuc   return ((char)f < (int)f); // no warning
766f4a2713aSLionel Sambuc }
checkLessThanBinaryOpIntCompare1(void)767f4a2713aSLionel Sambuc int checkLessThanBinaryOpIntCompare1(void) {
768f4a2713aSLionel Sambuc   int res;
769f4a2713aSLionel Sambuc   int f= 3;
770f4a2713aSLionel Sambuc   res = (f + 3 < f + 3);  // expected-warning {{comparison of identical expressions always evaluates to false}}
771f4a2713aSLionel Sambuc   return (0);
772f4a2713aSLionel Sambuc }
checkLessThanBinaryOpIntCompare2(void)773f4a2713aSLionel Sambuc int checkLessThanBinaryOpIntCompare2(void) {
774f4a2713aSLionel Sambuc   int f = 7;
775f4a2713aSLionel Sambuc   int g = 7;
776f4a2713aSLionel Sambuc   return (f + 3 < g + 3); // no warning
777f4a2713aSLionel Sambuc }
checkLessThanBinaryOpIntCompare3(void)778f4a2713aSLionel Sambuc int checkLessThanBinaryOpIntCompare3(void) {
779f4a2713aSLionel Sambuc   int res;
780f4a2713aSLionel Sambuc   int f= 3;
781f4a2713aSLionel Sambuc   res = ((int)f + 3 < (int)f + 3);  // expected-warning {{comparison of identical expressions always evaluates to false}}
782f4a2713aSLionel Sambuc   return (0);
783f4a2713aSLionel Sambuc }
checkLessThanBinaryOpIntCompare4(void)784f4a2713aSLionel Sambuc int checkLessThanBinaryOpIntCompare4(void) {
785f4a2713aSLionel Sambuc   int res;
786f4a2713aSLionel Sambuc   int f= 3;
787f4a2713aSLionel Sambuc   res = ((int)f + 3 < (char)f + 3);  // no warning
788f4a2713aSLionel Sambuc   return (0);
789f4a2713aSLionel Sambuc }
790f4a2713aSLionel Sambuc 
checkLessThanNestedBinaryOpIntCompare1(void)791f4a2713aSLionel Sambuc int checkLessThanNestedBinaryOpIntCompare1(void) {
792f4a2713aSLionel Sambuc   int res;
793f4a2713aSLionel Sambuc   int t= 1;
794f4a2713aSLionel Sambuc   int u= 2;
795f4a2713aSLionel Sambuc   int f= 3;
796f4a2713aSLionel Sambuc   res = (((int)f + (3 - u)*t) < ((int)f + (3 - u)*t));  // expected-warning {{comparison of identical expressions always evaluates to false}}
797f4a2713aSLionel Sambuc   return (0);
798f4a2713aSLionel Sambuc }
799f4a2713aSLionel Sambuc 
checkLessThanNestedBinaryOpIntCompare2(void)800f4a2713aSLionel Sambuc int checkLessThanNestedBinaryOpIntCompare2(void) {
801f4a2713aSLionel Sambuc   int res;
802f4a2713aSLionel Sambuc   int t= 1;
803f4a2713aSLionel Sambuc   int u= 2;
804f4a2713aSLionel Sambuc   int f= 3;
805f4a2713aSLionel Sambuc   res = (((int)f + (u - 3)*t) < ((int)f + (3 - u)*t));  // no warning
806f4a2713aSLionel Sambuc   return (0);
807f4a2713aSLionel Sambuc }
808f4a2713aSLionel Sambuc 
checkLessThanNestedBinaryOpIntCompare3(void)809f4a2713aSLionel Sambuc int checkLessThanNestedBinaryOpIntCompare3(void) {
810f4a2713aSLionel Sambuc   int res;
811f4a2713aSLionel Sambuc   int t= 1;
812f4a2713aSLionel Sambuc   int u= 2;
813f4a2713aSLionel Sambuc   int f= 3;
814f4a2713aSLionel Sambuc   res = (((int)f + (u - 3)*t) < ((int)f + (3 - u)*(t + u < t + u)));  // expected-warning {{comparison of identical expressions always evaluates to false}}
815f4a2713aSLionel Sambuc   return (0);
816f4a2713aSLionel Sambuc }
817f4a2713aSLionel Sambuc 
818f4a2713aSLionel Sambuc /* end LT with int */
819f4a2713aSLionel Sambuc 
820f4a2713aSLionel Sambuc /* end LT */
821f4a2713aSLionel Sambuc 
822f4a2713aSLionel Sambuc 
823f4a2713aSLionel Sambuc /* GT */
824f4a2713aSLionel Sambuc 
825f4a2713aSLionel Sambuc /* GT with float */
826f4a2713aSLionel Sambuc 
checkGreaterThanFloatLiteralCompare1(void)827f4a2713aSLionel Sambuc int checkGreaterThanFloatLiteralCompare1(void) {
828f4a2713aSLionel Sambuc   return (5.14F > 5.14F); // expected-warning {{comparison of identical expressions always evaluates to false}}
829f4a2713aSLionel Sambuc }
830f4a2713aSLionel Sambuc 
checkGreaterThanFloatLiteralCompare2(void)831f4a2713aSLionel Sambuc int checkGreaterThanFloatLiteralCompare2(void) {
832f4a2713aSLionel Sambuc   return (6.14F > 7.14F); // no warning
833f4a2713aSLionel Sambuc }
834f4a2713aSLionel Sambuc 
checkGreaterThanFloatDeclCompare1(void)835f4a2713aSLionel Sambuc int checkGreaterThanFloatDeclCompare1(void) {
836f4a2713aSLionel Sambuc   float f = 7.1F;
837f4a2713aSLionel Sambuc   float g = 7.1F;
838f4a2713aSLionel Sambuc 
839f4a2713aSLionel Sambuc   return (f > g); // no warning
840f4a2713aSLionel Sambuc }
841f4a2713aSLionel Sambuc 
checkGreaterThanFloatDeclCompare12(void)842f4a2713aSLionel Sambuc int checkGreaterThanFloatDeclCompare12(void) {
843f4a2713aSLionel Sambuc   float f = 7.1F;
844f4a2713aSLionel Sambuc   return (f > f); // expected-warning {{comparison of identical expressions always evaluates to false}}
845f4a2713aSLionel Sambuc }
846f4a2713aSLionel Sambuc 
847f4a2713aSLionel Sambuc 
checkGreaterThanFloatDeclCompare3(void)848f4a2713aSLionel Sambuc int checkGreaterThanFloatDeclCompare3(void) {
849f4a2713aSLionel Sambuc   float f = 7.1F;
850f4a2713aSLionel Sambuc   return (f > 7.1F); // no warning
851f4a2713aSLionel Sambuc }
852f4a2713aSLionel Sambuc 
checkGreaterThanFloatDeclCompare4(void)853f4a2713aSLionel Sambuc int checkGreaterThanFloatDeclCompare4(void) {
854f4a2713aSLionel Sambuc   float f = 7.1F;
855f4a2713aSLionel Sambuc   return (7.1F > f); // no warning
856f4a2713aSLionel Sambuc }
857f4a2713aSLionel Sambuc 
checkGreaterThanFloatDeclCompare5(void)858f4a2713aSLionel Sambuc int checkGreaterThanFloatDeclCompare5(void) {
859f4a2713aSLionel Sambuc   float f = 7.1F;
860f4a2713aSLionel Sambuc   int t = 7;
861f4a2713aSLionel Sambuc   return (t > f); // no warning
862f4a2713aSLionel Sambuc }
863f4a2713aSLionel Sambuc 
checkGreaterThanFloatDeclCompare6(void)864f4a2713aSLionel Sambuc int checkGreaterThanFloatDeclCompare6(void) {
865f4a2713aSLionel Sambuc   float f = 7.1F;
866f4a2713aSLionel Sambuc   int t = 7;
867f4a2713aSLionel Sambuc   return (f > t); // no warning
868f4a2713aSLionel Sambuc }
869f4a2713aSLionel Sambuc 
checkGreaterThanCastFloatDeclCompare11(void)870f4a2713aSLionel Sambuc int checkGreaterThanCastFloatDeclCompare11(void) {
871f4a2713aSLionel Sambuc   float f = 7.1F;
872f4a2713aSLionel Sambuc   return ((int)f > (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
873f4a2713aSLionel Sambuc }
checkGreaterThanCastFloatDeclCompare12(void)874f4a2713aSLionel Sambuc int checkGreaterThanCastFloatDeclCompare12(void) {
875f4a2713aSLionel Sambuc   float f = 7.1F;
876f4a2713aSLionel Sambuc   return ((char)f > (int)f); // no warning
877f4a2713aSLionel Sambuc }
checkGreaterThanBinaryOpFloatCompare1(void)878f4a2713aSLionel Sambuc int checkGreaterThanBinaryOpFloatCompare1(void) {
879f4a2713aSLionel Sambuc   int res;
880f4a2713aSLionel Sambuc   float f= 3.14F;
881f4a2713aSLionel Sambuc   res = (f + 3.14F > f + 3.14F);  // no warning
882f4a2713aSLionel Sambuc   return (0);
883f4a2713aSLionel Sambuc }
checkGreaterThanBinaryOpFloatCompare2(void)884f4a2713aSLionel Sambuc int checkGreaterThanBinaryOpFloatCompare2(void) {
885f4a2713aSLionel Sambuc   float f = 7.1F;
886f4a2713aSLionel Sambuc   float g = 7.1F;
887f4a2713aSLionel Sambuc   return (f + 3.14F > g + 3.14F); // no warning
888f4a2713aSLionel Sambuc }
checkGreaterThanBinaryOpFloatCompare3(void)889f4a2713aSLionel Sambuc int checkGreaterThanBinaryOpFloatCompare3(void) {
890f4a2713aSLionel Sambuc   int res;
891f4a2713aSLionel Sambuc   float f= 3.14F;
892f4a2713aSLionel Sambuc   res = ((int)f + 3.14F > (int)f + 3.14F);  // no warning
893f4a2713aSLionel Sambuc   return (0);
894f4a2713aSLionel Sambuc }
checkGreaterThanBinaryOpFloatCompare4(void)895f4a2713aSLionel Sambuc int checkGreaterThanBinaryOpFloatCompare4(void) {
896f4a2713aSLionel Sambuc   int res;
897f4a2713aSLionel Sambuc   float f= 3.14F;
898f4a2713aSLionel Sambuc   res = ((int)f + 3.14F > (char)f + 3.14F);  // no warning
899f4a2713aSLionel Sambuc   return (0);
900f4a2713aSLionel Sambuc }
901f4a2713aSLionel Sambuc 
checkGreaterThanNestedBinaryOpFloatCompare1(void)902f4a2713aSLionel Sambuc int checkGreaterThanNestedBinaryOpFloatCompare1(void) {
903f4a2713aSLionel Sambuc   int res;
904f4a2713aSLionel Sambuc   int t= 1;
905f4a2713aSLionel Sambuc   int u= 2;
906f4a2713aSLionel Sambuc   float f= 3.14F;
907f4a2713aSLionel Sambuc   res = (((int)f + (3.14F - u)*t) > ((int)f + (3.14F - u)*t));  // no warning
908f4a2713aSLionel Sambuc   return (0);
909f4a2713aSLionel Sambuc }
910f4a2713aSLionel Sambuc 
checkGreaterThanNestedBinaryOpFloatCompare2(void)911f4a2713aSLionel Sambuc int checkGreaterThanNestedBinaryOpFloatCompare2(void) {
912f4a2713aSLionel Sambuc   int res;
913f4a2713aSLionel Sambuc   int t= 1;
914f4a2713aSLionel Sambuc   int u= 2;
915f4a2713aSLionel Sambuc   float f= 3.14F;
916f4a2713aSLionel Sambuc   res = (((int)f + (u - 3.14F)*t) > ((int)f + (3.14F - u)*t));  // no warning
917f4a2713aSLionel Sambuc   return (0);
918f4a2713aSLionel Sambuc }
919f4a2713aSLionel Sambuc 
checkGreaterThanNestedBinaryOpFloatCompare3(void)920f4a2713aSLionel Sambuc int checkGreaterThanNestedBinaryOpFloatCompare3(void) {
921f4a2713aSLionel Sambuc   int res;
922f4a2713aSLionel Sambuc   int t= 1;
923f4a2713aSLionel Sambuc   int u= 2;
924f4a2713aSLionel Sambuc   float f= 3.14F;
925f4a2713aSLionel Sambuc   res = (((int)f + (u - 3.14F)*t) > ((int)f + (3.14F - u)*(f + t > f + t)));  // no warning
926f4a2713aSLionel Sambuc   return (0);
927f4a2713aSLionel Sambuc }
928f4a2713aSLionel Sambuc 
929f4a2713aSLionel Sambuc /*  end GT with float */
930f4a2713aSLionel Sambuc 
931f4a2713aSLionel Sambuc /*  GT with int */
932f4a2713aSLionel Sambuc 
933f4a2713aSLionel Sambuc 
checkGreaterThanIntLiteralCompare1(void)934f4a2713aSLionel Sambuc int checkGreaterThanIntLiteralCompare1(void) {
935f4a2713aSLionel Sambuc   return (5 > 5); // expected-warning {{comparison of identical expressions always evaluates to false}}
936f4a2713aSLionel Sambuc }
937f4a2713aSLionel Sambuc 
checkGreaterThanIntLiteralCompare2(void)938f4a2713aSLionel Sambuc int checkGreaterThanIntLiteralCompare2(void) {
939f4a2713aSLionel Sambuc   return (6 > 7); // no warning
940f4a2713aSLionel Sambuc }
941f4a2713aSLionel Sambuc 
checkGreaterThanIntDeclCompare1(void)942f4a2713aSLionel Sambuc int checkGreaterThanIntDeclCompare1(void) {
943f4a2713aSLionel Sambuc   int f = 7;
944f4a2713aSLionel Sambuc   int g = 7;
945f4a2713aSLionel Sambuc 
946f4a2713aSLionel Sambuc   return (f > g); // no warning
947f4a2713aSLionel Sambuc }
948f4a2713aSLionel Sambuc 
checkGreaterThanIntDeclCompare3(void)949f4a2713aSLionel Sambuc int checkGreaterThanIntDeclCompare3(void) {
950f4a2713aSLionel Sambuc   int f = 7;
951f4a2713aSLionel Sambuc   return (f > 7); // no warning
952f4a2713aSLionel Sambuc }
953f4a2713aSLionel Sambuc 
checkGreaterThanIntDeclCompare4(void)954f4a2713aSLionel Sambuc int checkGreaterThanIntDeclCompare4(void) {
955f4a2713aSLionel Sambuc   int f = 7;
956f4a2713aSLionel Sambuc   return (7 > f); // no warning
957f4a2713aSLionel Sambuc }
958f4a2713aSLionel Sambuc 
checkGreaterThanCastIntDeclCompare11(void)959f4a2713aSLionel Sambuc int checkGreaterThanCastIntDeclCompare11(void) {
960f4a2713aSLionel Sambuc   int f = 7;
961f4a2713aSLionel Sambuc   return ((int)f > (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}}
962f4a2713aSLionel Sambuc }
checkGreaterThanCastIntDeclCompare12(void)963f4a2713aSLionel Sambuc int checkGreaterThanCastIntDeclCompare12(void) {
964f4a2713aSLionel Sambuc   int f = 7;
965f4a2713aSLionel Sambuc   return ((char)f > (int)f); // no warning
966f4a2713aSLionel Sambuc }
checkGreaterThanBinaryOpIntCompare1(void)967f4a2713aSLionel Sambuc int checkGreaterThanBinaryOpIntCompare1(void) {
968f4a2713aSLionel Sambuc   int res;
969f4a2713aSLionel Sambuc   int f= 3;
970f4a2713aSLionel Sambuc   res = (f + 3 > f + 3);  // expected-warning {{comparison of identical expressions always evaluates to false}}
971f4a2713aSLionel Sambuc   return (0);
972f4a2713aSLionel Sambuc }
checkGreaterThanBinaryOpIntCompare2(void)973f4a2713aSLionel Sambuc int checkGreaterThanBinaryOpIntCompare2(void) {
974f4a2713aSLionel Sambuc   int f = 7;
975f4a2713aSLionel Sambuc   int g = 7;
976f4a2713aSLionel Sambuc   return (f + 3 > g + 3); // no warning
977f4a2713aSLionel Sambuc }
checkGreaterThanBinaryOpIntCompare3(void)978f4a2713aSLionel Sambuc int checkGreaterThanBinaryOpIntCompare3(void) {
979f4a2713aSLionel Sambuc   int res;
980f4a2713aSLionel Sambuc   int f= 3;
981f4a2713aSLionel Sambuc   res = ((int)f + 3 > (int)f + 3);  // expected-warning {{comparison of identical expressions always evaluates to false}}
982f4a2713aSLionel Sambuc   return (0);
983f4a2713aSLionel Sambuc }
checkGreaterThanBinaryOpIntCompare4(void)984f4a2713aSLionel Sambuc int checkGreaterThanBinaryOpIntCompare4(void) {
985f4a2713aSLionel Sambuc   int res;
986f4a2713aSLionel Sambuc   int f= 3;
987f4a2713aSLionel Sambuc   res = ((int)f + 3 > (char)f + 3);  // no warning
988f4a2713aSLionel Sambuc   return (0);
989f4a2713aSLionel Sambuc }
990f4a2713aSLionel Sambuc 
checkGreaterThanNestedBinaryOpIntCompare1(void)991f4a2713aSLionel Sambuc int checkGreaterThanNestedBinaryOpIntCompare1(void) {
992f4a2713aSLionel Sambuc   int res;
993f4a2713aSLionel Sambuc   int t= 1;
994f4a2713aSLionel Sambuc   int u= 2;
995f4a2713aSLionel Sambuc   int f= 3;
996f4a2713aSLionel Sambuc   res = (((int)f + (3 - u)*t) > ((int)f + (3 - u)*t));  // expected-warning {{comparison of identical expressions always evaluates to false}}
997f4a2713aSLionel Sambuc   return (0);
998f4a2713aSLionel Sambuc }
999f4a2713aSLionel Sambuc 
checkGreaterThanNestedBinaryOpIntCompare2(void)1000f4a2713aSLionel Sambuc int checkGreaterThanNestedBinaryOpIntCompare2(void) {
1001f4a2713aSLionel Sambuc   int res;
1002f4a2713aSLionel Sambuc   int t= 1;
1003f4a2713aSLionel Sambuc   int u= 2;
1004f4a2713aSLionel Sambuc   int f= 3;
1005f4a2713aSLionel Sambuc   res = (((int)f + (u - 3)*t) > ((int)f + (3 - u)*t));  // no warning
1006f4a2713aSLionel Sambuc   return (0);
1007f4a2713aSLionel Sambuc }
1008f4a2713aSLionel Sambuc 
checkGreaterThanNestedBinaryOpIntCompare3(void)1009f4a2713aSLionel Sambuc int checkGreaterThanNestedBinaryOpIntCompare3(void) {
1010f4a2713aSLionel Sambuc   int res;
1011f4a2713aSLionel Sambuc   int t= 1;
1012f4a2713aSLionel Sambuc   int u= 2;
1013f4a2713aSLionel Sambuc   int f= 3;
1014f4a2713aSLionel Sambuc   res = (((int)f + (u - 3)*t) > ((int)f + (3 - u)*(t + u > t + u)));  // expected-warning {{comparison of identical expressions always evaluates to false}}
1015f4a2713aSLionel Sambuc   return (0);
1016f4a2713aSLionel Sambuc }
1017f4a2713aSLionel Sambuc 
1018f4a2713aSLionel Sambuc /* end GT with int */
1019f4a2713aSLionel Sambuc 
1020f4a2713aSLionel Sambuc /* end GT */
1021*0a6a1f1dSLionel Sambuc 
1022*0a6a1f1dSLionel Sambuc 
1023*0a6a1f1dSLionel Sambuc /* Checking use of identical expressions in conditional operator*/
1024*0a6a1f1dSLionel Sambuc 
test_unsigned(unsigned a)1025*0a6a1f1dSLionel Sambuc unsigned test_unsigned(unsigned a) {
1026*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1027*0a6a1f1dSLionel Sambuc   a = a > 5 ? b : b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1028*0a6a1f1dSLionel Sambuc   return a;
1029*0a6a1f1dSLionel Sambuc }
1030*0a6a1f1dSLionel Sambuc 
test_signed()1031*0a6a1f1dSLionel Sambuc void test_signed() {
1032*0a6a1f1dSLionel Sambuc   int a = 0;
1033*0a6a1f1dSLionel Sambuc   a = a > 5 ? a : a; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1034*0a6a1f1dSLionel Sambuc }
1035*0a6a1f1dSLionel Sambuc 
test_bool(bool a)1036*0a6a1f1dSLionel Sambuc void test_bool(bool a) {
1037*0a6a1f1dSLionel Sambuc   a = a > 0 ? a : a; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1038*0a6a1f1dSLionel Sambuc }
1039*0a6a1f1dSLionel Sambuc 
test_float()1040*0a6a1f1dSLionel Sambuc void test_float() {
1041*0a6a1f1dSLionel Sambuc   float a = 0;
1042*0a6a1f1dSLionel Sambuc   float b = 0;
1043*0a6a1f1dSLionel Sambuc   a = a > 5 ? a : a; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1044*0a6a1f1dSLionel Sambuc }
1045*0a6a1f1dSLionel Sambuc 
test_string()1046*0a6a1f1dSLionel Sambuc const char *test_string() {
1047*0a6a1f1dSLionel Sambuc   float a = 0;
1048*0a6a1f1dSLionel Sambuc   return a > 5 ? "abc" : "abc"; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1049*0a6a1f1dSLionel Sambuc }
1050*0a6a1f1dSLionel Sambuc 
test_unsigned_expr()1051*0a6a1f1dSLionel Sambuc void test_unsigned_expr() {
1052*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1053*0a6a1f1dSLionel Sambuc   unsigned b = 0;
1054*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+b : a+b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1055*0a6a1f1dSLionel Sambuc }
1056*0a6a1f1dSLionel Sambuc 
test_signed_expr()1057*0a6a1f1dSLionel Sambuc void test_signed_expr() {
1058*0a6a1f1dSLionel Sambuc   int a = 0;
1059*0a6a1f1dSLionel Sambuc   int b = 1;
1060*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+b : a+b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1061*0a6a1f1dSLionel Sambuc }
1062*0a6a1f1dSLionel Sambuc 
test_bool_expr(bool a)1063*0a6a1f1dSLionel Sambuc void test_bool_expr(bool a) {
1064*0a6a1f1dSLionel Sambuc   bool b = 0;
1065*0a6a1f1dSLionel Sambuc   a = a > 0 ? a&&b : a&&b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1066*0a6a1f1dSLionel Sambuc }
1067*0a6a1f1dSLionel Sambuc 
test_unsigned_expr_negative()1068*0a6a1f1dSLionel Sambuc void test_unsigned_expr_negative() {
1069*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1070*0a6a1f1dSLionel Sambuc   unsigned b = 0;
1071*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+b : b+a; // no warning
1072*0a6a1f1dSLionel Sambuc }
1073*0a6a1f1dSLionel Sambuc 
test_signed_expr_negative()1074*0a6a1f1dSLionel Sambuc void test_signed_expr_negative() {
1075*0a6a1f1dSLionel Sambuc   int a = 0;
1076*0a6a1f1dSLionel Sambuc   int b = 1;
1077*0a6a1f1dSLionel Sambuc   a = a > 5 ? b+a : a+b; // no warning
1078*0a6a1f1dSLionel Sambuc }
1079*0a6a1f1dSLionel Sambuc 
test_bool_expr_negative(bool a)1080*0a6a1f1dSLionel Sambuc void test_bool_expr_negative(bool a) {
1081*0a6a1f1dSLionel Sambuc   bool b = 0;
1082*0a6a1f1dSLionel Sambuc   a = a > 0 ? a&&b : b&&a; // no warning
1083*0a6a1f1dSLionel Sambuc }
1084*0a6a1f1dSLionel Sambuc 
test_float_expr_positive()1085*0a6a1f1dSLionel Sambuc void test_float_expr_positive() {
1086*0a6a1f1dSLionel Sambuc   float a = 0;
1087*0a6a1f1dSLionel Sambuc   float b = 0;
1088*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+b : a+b; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1089*0a6a1f1dSLionel Sambuc }
1090*0a6a1f1dSLionel Sambuc 
test_expr_positive_func()1091*0a6a1f1dSLionel Sambuc void test_expr_positive_func() {
1092*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1093*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1094*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+func() : a+func(); // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1095*0a6a1f1dSLionel Sambuc }
1096*0a6a1f1dSLionel Sambuc 
test_expr_negative_func()1097*0a6a1f1dSLionel Sambuc void test_expr_negative_func() {
1098*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1099*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1100*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+func() : a+func2(); // no warning
1101*0a6a1f1dSLionel Sambuc }
1102*0a6a1f1dSLionel Sambuc 
test_expr_positive_funcParam()1103*0a6a1f1dSLionel Sambuc void test_expr_positive_funcParam() {
1104*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1105*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1106*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+funcParam(b) : a+funcParam(b); // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1107*0a6a1f1dSLionel Sambuc }
1108*0a6a1f1dSLionel Sambuc 
test_expr_negative_funcParam()1109*0a6a1f1dSLionel Sambuc void test_expr_negative_funcParam() {
1110*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1111*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1112*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+funcParam(a) : a+funcParam(b); // no warning
1113*0a6a1f1dSLionel Sambuc }
1114*0a6a1f1dSLionel Sambuc 
test_expr_positive_inc()1115*0a6a1f1dSLionel Sambuc void test_expr_positive_inc() {
1116*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1117*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1118*0a6a1f1dSLionel Sambuc   a = a > 5 ? a++ : a++; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1119*0a6a1f1dSLionel Sambuc }
1120*0a6a1f1dSLionel Sambuc 
test_expr_negative_inc()1121*0a6a1f1dSLionel Sambuc void test_expr_negative_inc() {
1122*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1123*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1124*0a6a1f1dSLionel Sambuc   a = a > 5 ? a++ : b++; // no warning
1125*0a6a1f1dSLionel Sambuc }
1126*0a6a1f1dSLionel Sambuc 
test_expr_positive_assign()1127*0a6a1f1dSLionel Sambuc void test_expr_positive_assign() {
1128*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1129*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1130*0a6a1f1dSLionel Sambuc   a = a > 5 ? a=1 : a=1;  // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1131*0a6a1f1dSLionel Sambuc }
1132*0a6a1f1dSLionel Sambuc 
test_expr_negative_assign()1133*0a6a1f1dSLionel Sambuc void test_expr_negative_assign() {
1134*0a6a1f1dSLionel Sambuc   unsigned a = 0;
1135*0a6a1f1dSLionel Sambuc   unsigned b = 1;
1136*0a6a1f1dSLionel Sambuc   a = a > 5 ? a=1 : a=2; // no warning
1137*0a6a1f1dSLionel Sambuc }
1138*0a6a1f1dSLionel Sambuc 
test_signed_nested_expr()1139*0a6a1f1dSLionel Sambuc void test_signed_nested_expr() {
1140*0a6a1f1dSLionel Sambuc   int a = 0;
1141*0a6a1f1dSLionel Sambuc   int b = 1;
1142*0a6a1f1dSLionel Sambuc   int c = 3;
1143*0a6a1f1dSLionel Sambuc   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}}
1144*0a6a1f1dSLionel Sambuc }
1145*0a6a1f1dSLionel Sambuc 
test_signed_nested_expr_negative()1146*0a6a1f1dSLionel Sambuc void test_signed_nested_expr_negative() {
1147*0a6a1f1dSLionel Sambuc   int a = 0;
1148*0a6a1f1dSLionel Sambuc   int b = 1;
1149*0a6a1f1dSLionel Sambuc   int c = 3;
1150*0a6a1f1dSLionel Sambuc   a = a > 5 ? a+b+(c+a)*(a + b*(c+a)) : a+b+(c+a)*(a + b*(a+c)); // no warning
1151*0a6a1f1dSLionel Sambuc }
1152*0a6a1f1dSLionel Sambuc 
test_signed_nested_cond_expr_negative()1153*0a6a1f1dSLionel Sambuc void test_signed_nested_cond_expr_negative() {
1154*0a6a1f1dSLionel Sambuc   int a = 0;
1155*0a6a1f1dSLionel Sambuc   int b = 1;
1156*0a6a1f1dSLionel Sambuc   int c = 3;
1157*0a6a1f1dSLionel Sambuc   a = a > 5 ? (b > 5 ? 1 : 4) : (b > 5 ? 2 : 4); // no warning
1158*0a6a1f1dSLionel Sambuc }
1159*0a6a1f1dSLionel Sambuc 
test_signed_nested_cond_expr()1160*0a6a1f1dSLionel Sambuc void test_signed_nested_cond_expr() {
1161*0a6a1f1dSLionel Sambuc   int a = 0;
1162*0a6a1f1dSLionel Sambuc   int b = 1;
1163*0a6a1f1dSLionel Sambuc   int c = 3;
1164*0a6a1f1dSLionel Sambuc   a = a > 5 ? (b > 5 ? 1 : 4) : (b > 5 ? 4 : 4); // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1165*0a6a1f1dSLionel Sambuc }
1166*0a6a1f1dSLionel Sambuc 
test_identical_branches1(bool b)1167*0a6a1f1dSLionel Sambuc void test_identical_branches1(bool b) {
1168*0a6a1f1dSLionel Sambuc   int i = 0;
1169*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1170*0a6a1f1dSLionel Sambuc     ++i;
1171*0a6a1f1dSLionel Sambuc   } else {
1172*0a6a1f1dSLionel Sambuc     ++i;
1173*0a6a1f1dSLionel Sambuc   }
1174*0a6a1f1dSLionel Sambuc }
1175*0a6a1f1dSLionel Sambuc 
test_identical_branches2(bool b)1176*0a6a1f1dSLionel Sambuc void test_identical_branches2(bool b) {
1177*0a6a1f1dSLionel Sambuc   int i = 0;
1178*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1179*0a6a1f1dSLionel Sambuc     ++i;
1180*0a6a1f1dSLionel Sambuc   } else
1181*0a6a1f1dSLionel Sambuc     ++i;
1182*0a6a1f1dSLionel Sambuc }
1183*0a6a1f1dSLionel Sambuc 
test_identical_branches3(bool b)1184*0a6a1f1dSLionel Sambuc void test_identical_branches3(bool b) {
1185*0a6a1f1dSLionel Sambuc   int i = 0;
1186*0a6a1f1dSLionel Sambuc   if (b) { // no warning
1187*0a6a1f1dSLionel Sambuc     ++i;
1188*0a6a1f1dSLionel Sambuc   } else {
1189*0a6a1f1dSLionel Sambuc     i++;
1190*0a6a1f1dSLionel Sambuc   }
1191*0a6a1f1dSLionel Sambuc }
1192*0a6a1f1dSLionel Sambuc 
test_identical_branches4(bool b)1193*0a6a1f1dSLionel Sambuc void test_identical_branches4(bool b) {
1194*0a6a1f1dSLionel Sambuc   int i = 0;
1195*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1196*0a6a1f1dSLionel Sambuc   } else {
1197*0a6a1f1dSLionel Sambuc   }
1198*0a6a1f1dSLionel Sambuc }
1199*0a6a1f1dSLionel Sambuc 
test_identical_branches_break(bool b)1200*0a6a1f1dSLionel Sambuc void test_identical_branches_break(bool b) {
1201*0a6a1f1dSLionel Sambuc   while (true) {
1202*0a6a1f1dSLionel Sambuc     if (b) // expected-warning {{true and false branches are identical}}
1203*0a6a1f1dSLionel Sambuc       break;
1204*0a6a1f1dSLionel Sambuc     else
1205*0a6a1f1dSLionel Sambuc       break;
1206*0a6a1f1dSLionel Sambuc   }
1207*0a6a1f1dSLionel Sambuc }
1208*0a6a1f1dSLionel Sambuc 
test_identical_branches_continue(bool b)1209*0a6a1f1dSLionel Sambuc void test_identical_branches_continue(bool b) {
1210*0a6a1f1dSLionel Sambuc   while (true) {
1211*0a6a1f1dSLionel Sambuc     if (b) // expected-warning {{true and false branches are identical}}
1212*0a6a1f1dSLionel Sambuc       continue;
1213*0a6a1f1dSLionel Sambuc     else
1214*0a6a1f1dSLionel Sambuc       continue;
1215*0a6a1f1dSLionel Sambuc   }
1216*0a6a1f1dSLionel Sambuc }
1217*0a6a1f1dSLionel Sambuc 
test_identical_branches_func(bool b)1218*0a6a1f1dSLionel Sambuc void test_identical_branches_func(bool b) {
1219*0a6a1f1dSLionel Sambuc   if (b) // expected-warning {{true and false branches are identical}}
1220*0a6a1f1dSLionel Sambuc     func();
1221*0a6a1f1dSLionel Sambuc   else
1222*0a6a1f1dSLionel Sambuc     func();
1223*0a6a1f1dSLionel Sambuc }
1224*0a6a1f1dSLionel Sambuc 
test_identical_branches_func_arguments(bool b)1225*0a6a1f1dSLionel Sambuc void test_identical_branches_func_arguments(bool b) {
1226*0a6a1f1dSLionel Sambuc   if (b) // no-warning
1227*0a6a1f1dSLionel Sambuc     funcParam(1);
1228*0a6a1f1dSLionel Sambuc   else
1229*0a6a1f1dSLionel Sambuc     funcParam(2);
1230*0a6a1f1dSLionel Sambuc }
1231*0a6a1f1dSLionel Sambuc 
test_identical_branches_cast1(bool b)1232*0a6a1f1dSLionel Sambuc void test_identical_branches_cast1(bool b) {
1233*0a6a1f1dSLionel Sambuc   long v = -7;
1234*0a6a1f1dSLionel Sambuc   if (b) // no-warning
1235*0a6a1f1dSLionel Sambuc     v = (signed int) v;
1236*0a6a1f1dSLionel Sambuc   else
1237*0a6a1f1dSLionel Sambuc     v = (unsigned int) v;
1238*0a6a1f1dSLionel Sambuc }
1239*0a6a1f1dSLionel Sambuc 
test_identical_branches_cast2(bool b)1240*0a6a1f1dSLionel Sambuc void test_identical_branches_cast2(bool b) {
1241*0a6a1f1dSLionel Sambuc   long v = -7;
1242*0a6a1f1dSLionel Sambuc   if (b) // expected-warning {{true and false branches are identical}}
1243*0a6a1f1dSLionel Sambuc     v = (signed int) v;
1244*0a6a1f1dSLionel Sambuc   else
1245*0a6a1f1dSLionel Sambuc     v = (signed int) v;
1246*0a6a1f1dSLionel Sambuc }
1247*0a6a1f1dSLionel Sambuc 
test_identical_branches_return_int(bool b)1248*0a6a1f1dSLionel Sambuc int test_identical_branches_return_int(bool b) {
1249*0a6a1f1dSLionel Sambuc   int i = 0;
1250*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1251*0a6a1f1dSLionel Sambuc     i++;
1252*0a6a1f1dSLionel Sambuc     return i;
1253*0a6a1f1dSLionel Sambuc   } else {
1254*0a6a1f1dSLionel Sambuc     i++;
1255*0a6a1f1dSLionel Sambuc     return i;
1256*0a6a1f1dSLionel Sambuc   }
1257*0a6a1f1dSLionel Sambuc }
1258*0a6a1f1dSLionel Sambuc 
test_identical_branches_return_func(bool b)1259*0a6a1f1dSLionel Sambuc int test_identical_branches_return_func(bool b) {
1260*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1261*0a6a1f1dSLionel Sambuc     return func();
1262*0a6a1f1dSLionel Sambuc   } else {
1263*0a6a1f1dSLionel Sambuc     return func();
1264*0a6a1f1dSLionel Sambuc   }
1265*0a6a1f1dSLionel Sambuc }
1266*0a6a1f1dSLionel Sambuc 
test_identical_branches_for(bool b)1267*0a6a1f1dSLionel Sambuc void test_identical_branches_for(bool b) {
1268*0a6a1f1dSLionel Sambuc   int i;
1269*0a6a1f1dSLionel Sambuc   int j;
1270*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1271*0a6a1f1dSLionel Sambuc     for (i = 0, j = 0; i < 10; i++)
1272*0a6a1f1dSLionel Sambuc       j += 4;
1273*0a6a1f1dSLionel Sambuc   } else {
1274*0a6a1f1dSLionel Sambuc     for (i = 0, j = 0; i < 10; i++)
1275*0a6a1f1dSLionel Sambuc       j += 4;
1276*0a6a1f1dSLionel Sambuc   }
1277*0a6a1f1dSLionel Sambuc }
1278*0a6a1f1dSLionel Sambuc 
test_identical_branches_while(bool b)1279*0a6a1f1dSLionel Sambuc void test_identical_branches_while(bool b) {
1280*0a6a1f1dSLionel Sambuc   int i = 10;
1281*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1282*0a6a1f1dSLionel Sambuc     while (func())
1283*0a6a1f1dSLionel Sambuc       i--;
1284*0a6a1f1dSLionel Sambuc   } else {
1285*0a6a1f1dSLionel Sambuc     while (func())
1286*0a6a1f1dSLionel Sambuc       i--;
1287*0a6a1f1dSLionel Sambuc   }
1288*0a6a1f1dSLionel Sambuc }
1289*0a6a1f1dSLionel Sambuc 
test_identical_branches_while_2(bool b)1290*0a6a1f1dSLionel Sambuc void test_identical_branches_while_2(bool b) {
1291*0a6a1f1dSLionel Sambuc   int i = 10;
1292*0a6a1f1dSLionel Sambuc   if (b) { // no-warning
1293*0a6a1f1dSLionel Sambuc     while (func())
1294*0a6a1f1dSLionel Sambuc       i--;
1295*0a6a1f1dSLionel Sambuc   } else {
1296*0a6a1f1dSLionel Sambuc     while (func())
1297*0a6a1f1dSLionel Sambuc       i++;
1298*0a6a1f1dSLionel Sambuc   }
1299*0a6a1f1dSLionel Sambuc }
1300*0a6a1f1dSLionel Sambuc 
test_identical_branches_do_while(bool b)1301*0a6a1f1dSLionel Sambuc void test_identical_branches_do_while(bool b) {
1302*0a6a1f1dSLionel Sambuc   int i = 10;
1303*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1304*0a6a1f1dSLionel Sambuc     do {
1305*0a6a1f1dSLionel Sambuc       i--;
1306*0a6a1f1dSLionel Sambuc     } while (func());
1307*0a6a1f1dSLionel Sambuc   } else {
1308*0a6a1f1dSLionel Sambuc     do {
1309*0a6a1f1dSLionel Sambuc       i--;
1310*0a6a1f1dSLionel Sambuc     } while (func());
1311*0a6a1f1dSLionel Sambuc   }
1312*0a6a1f1dSLionel Sambuc }
1313*0a6a1f1dSLionel Sambuc 
test_identical_branches_if(bool b,int i)1314*0a6a1f1dSLionel Sambuc void test_identical_branches_if(bool b, int i) {
1315*0a6a1f1dSLionel Sambuc   if (b) { // expected-warning {{true and false branches are identical}}
1316*0a6a1f1dSLionel Sambuc     if (i < 5)
1317*0a6a1f1dSLionel Sambuc       i += 10;
1318*0a6a1f1dSLionel Sambuc   } else {
1319*0a6a1f1dSLionel Sambuc     if (i < 5)
1320*0a6a1f1dSLionel Sambuc       i += 10;
1321*0a6a1f1dSLionel Sambuc   }
1322*0a6a1f1dSLionel Sambuc }
1323*0a6a1f1dSLionel Sambuc 
test_identical_bitwise1()1324*0a6a1f1dSLionel Sambuc void test_identical_bitwise1() {
1325*0a6a1f1dSLionel Sambuc   int a = 5 | 5; // expected-warning {{identical expressions on both sides of bitwise operator}}
1326*0a6a1f1dSLionel Sambuc }
1327*0a6a1f1dSLionel Sambuc 
test_identical_bitwise2()1328*0a6a1f1dSLionel Sambuc void test_identical_bitwise2() {
1329*0a6a1f1dSLionel Sambuc   int a = 5;
1330*0a6a1f1dSLionel Sambuc   int b = a | a; // expected-warning {{identical expressions on both sides of bitwise operator}}
1331*0a6a1f1dSLionel Sambuc }
1332*0a6a1f1dSLionel Sambuc 
test_identical_bitwise3()1333*0a6a1f1dSLionel Sambuc void test_identical_bitwise3() {
1334*0a6a1f1dSLionel Sambuc   int a = 5;
1335*0a6a1f1dSLionel Sambuc   int b = (a | a); // expected-warning {{identical expressions on both sides of bitwise operator}}
1336*0a6a1f1dSLionel Sambuc }
1337*0a6a1f1dSLionel Sambuc 
test_identical_bitwise4()1338*0a6a1f1dSLionel Sambuc void test_identical_bitwise4() {
1339*0a6a1f1dSLionel Sambuc   int a = 4;
1340*0a6a1f1dSLionel Sambuc   int b = a | 4; // no-warning
1341*0a6a1f1dSLionel Sambuc }
1342*0a6a1f1dSLionel Sambuc 
test_identical_bitwise5()1343*0a6a1f1dSLionel Sambuc void test_identical_bitwise5() {
1344*0a6a1f1dSLionel Sambuc   int a = 4;
1345*0a6a1f1dSLionel Sambuc   int b = 4;
1346*0a6a1f1dSLionel Sambuc   int c = a | b; // no-warning
1347*0a6a1f1dSLionel Sambuc }
1348*0a6a1f1dSLionel Sambuc 
test_identical_bitwise6()1349*0a6a1f1dSLionel Sambuc void test_identical_bitwise6() {
1350*0a6a1f1dSLionel Sambuc   int a = 5;
1351*0a6a1f1dSLionel Sambuc   int b = a | 4 | a; // expected-warning {{identical expressions on both sides of bitwise operator}}
1352*0a6a1f1dSLionel Sambuc }
1353*0a6a1f1dSLionel Sambuc 
test_identical_bitwise7()1354*0a6a1f1dSLionel Sambuc void test_identical_bitwise7() {
1355*0a6a1f1dSLionel Sambuc   int a = 5;
1356*0a6a1f1dSLionel Sambuc   int b = func() | func(); // no-warning
1357*0a6a1f1dSLionel Sambuc }
1358*0a6a1f1dSLionel Sambuc 
test_identical_logical1(int a)1359*0a6a1f1dSLionel Sambuc void test_identical_logical1(int a) {
1360*0a6a1f1dSLionel Sambuc   if (a == 4 && a == 4) // expected-warning {{identical expressions on both sides of logical operator}}
1361*0a6a1f1dSLionel Sambuc     ;
1362*0a6a1f1dSLionel Sambuc }
1363*0a6a1f1dSLionel Sambuc 
test_identical_logical2(int a)1364*0a6a1f1dSLionel Sambuc void test_identical_logical2(int a) {
1365*0a6a1f1dSLionel Sambuc   if (a == 4 || a == 5 || a == 4) // expected-warning {{identical expressions on both sides of logical operator}}
1366*0a6a1f1dSLionel Sambuc     ;
1367*0a6a1f1dSLionel Sambuc }
1368*0a6a1f1dSLionel Sambuc 
test_identical_logical3(int a)1369*0a6a1f1dSLionel Sambuc void test_identical_logical3(int a) {
1370*0a6a1f1dSLionel Sambuc   if (a == 4 || a == 5 || a == 6) // no-warning
1371*0a6a1f1dSLionel Sambuc     ;
1372*0a6a1f1dSLionel Sambuc }
1373*0a6a1f1dSLionel Sambuc 
test_identical_logical4(int a)1374*0a6a1f1dSLionel Sambuc void test_identical_logical4(int a) {
1375*0a6a1f1dSLionel Sambuc   if (a == func() || a == func()) // no-warning
1376*0a6a1f1dSLionel Sambuc     ;
1377*0a6a1f1dSLionel Sambuc }
1378*0a6a1f1dSLionel Sambuc 
1379*0a6a1f1dSLionel Sambuc #pragma clang diagnostic push
1380*0a6a1f1dSLionel Sambuc #pragma clang diagnostic ignored "-Wlogical-op-parentheses"
test_identical_logical5(int x,int y)1381*0a6a1f1dSLionel Sambuc void test_identical_logical5(int x, int y) {
1382*0a6a1f1dSLionel Sambuc   if (x == 4 && y == 5 || x == 4 && y == 6) // no-warning
1383*0a6a1f1dSLionel Sambuc     ;
1384*0a6a1f1dSLionel Sambuc }
1385*0a6a1f1dSLionel Sambuc 
test_identical_logical6(int x,int y)1386*0a6a1f1dSLionel Sambuc void test_identical_logical6(int x, int y) {
1387*0a6a1f1dSLionel Sambuc   if (x == 4 && y == 5 || x == 4 && y == 5) // expected-warning {{identical expressions on both sides of logical operator}}
1388*0a6a1f1dSLionel Sambuc     ;
1389*0a6a1f1dSLionel Sambuc }
1390*0a6a1f1dSLionel Sambuc 
test_identical_logical7(int x,int y)1391*0a6a1f1dSLionel Sambuc void test_identical_logical7(int x, int y) {
1392*0a6a1f1dSLionel Sambuc   // FIXME: We should warn here
1393*0a6a1f1dSLionel Sambuc   if (x == 4 && y == 5 || x == 4)
1394*0a6a1f1dSLionel Sambuc     ;
1395*0a6a1f1dSLionel Sambuc }
1396*0a6a1f1dSLionel Sambuc 
test_identical_logical8(int x,int y)1397*0a6a1f1dSLionel Sambuc void test_identical_logical8(int x, int y) {
1398*0a6a1f1dSLionel Sambuc   // FIXME: We should warn here
1399*0a6a1f1dSLionel Sambuc   if (x == 4 || y == 5 && x == 4)
1400*0a6a1f1dSLionel Sambuc     ;
1401*0a6a1f1dSLionel Sambuc }
1402*0a6a1f1dSLionel Sambuc 
test_identical_logical9(int x,int y)1403*0a6a1f1dSLionel Sambuc void test_identical_logical9(int x, int y) {
1404*0a6a1f1dSLionel Sambuc   // FIXME: We should warn here
1405*0a6a1f1dSLionel Sambuc   if (x == 4 || x == 4 && y == 5)
1406*0a6a1f1dSLionel Sambuc     ;
1407*0a6a1f1dSLionel Sambuc }
1408*0a6a1f1dSLionel Sambuc #pragma clang diagnostic pop
1409*0a6a1f1dSLionel Sambuc 
test_warn_chained_if_stmts_1(int x)1410*0a6a1f1dSLionel Sambuc void test_warn_chained_if_stmts_1(int x) {
1411*0a6a1f1dSLionel Sambuc   if (x == 1)
1412*0a6a1f1dSLionel Sambuc     ;
1413*0a6a1f1dSLionel Sambuc   else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1414*0a6a1f1dSLionel Sambuc     ;
1415*0a6a1f1dSLionel Sambuc }
1416*0a6a1f1dSLionel Sambuc 
test_warn_chained_if_stmts_2(int x)1417*0a6a1f1dSLionel Sambuc void test_warn_chained_if_stmts_2(int x) {
1418*0a6a1f1dSLionel Sambuc   if (x == 1)
1419*0a6a1f1dSLionel Sambuc     ;
1420*0a6a1f1dSLionel Sambuc   else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1421*0a6a1f1dSLionel Sambuc     ;
1422*0a6a1f1dSLionel Sambuc   else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1423*0a6a1f1dSLionel Sambuc     ;
1424*0a6a1f1dSLionel Sambuc }
1425*0a6a1f1dSLionel Sambuc 
test_warn_chained_if_stmts_3(int x)1426*0a6a1f1dSLionel Sambuc void test_warn_chained_if_stmts_3(int x) {
1427*0a6a1f1dSLionel Sambuc   if (x == 1)
1428*0a6a1f1dSLionel Sambuc     ;
1429*0a6a1f1dSLionel Sambuc   else if (x == 2)
1430*0a6a1f1dSLionel Sambuc     ;
1431*0a6a1f1dSLionel Sambuc   else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1432*0a6a1f1dSLionel Sambuc     ;
1433*0a6a1f1dSLionel Sambuc }
1434*0a6a1f1dSLionel Sambuc 
test_warn_chained_if_stmts_4(int x)1435*0a6a1f1dSLionel Sambuc void test_warn_chained_if_stmts_4(int x) {
1436*0a6a1f1dSLionel Sambuc   if (x == 1)
1437*0a6a1f1dSLionel Sambuc     ;
1438*0a6a1f1dSLionel Sambuc   else if (func())
1439*0a6a1f1dSLionel Sambuc     ;
1440*0a6a1f1dSLionel Sambuc   else if (x == 1) // expected-warning {{expression is identical to previous condition}}
1441*0a6a1f1dSLionel Sambuc     ;
1442*0a6a1f1dSLionel Sambuc }
1443*0a6a1f1dSLionel Sambuc 
test_warn_chained_if_stmts_5(int x)1444*0a6a1f1dSLionel Sambuc void test_warn_chained_if_stmts_5(int x) {
1445*0a6a1f1dSLionel Sambuc   if (x & 1)
1446*0a6a1f1dSLionel Sambuc     ;
1447*0a6a1f1dSLionel Sambuc   else if (x & 1) // expected-warning {{expression is identical to previous condition}}
1448*0a6a1f1dSLionel Sambuc     ;
1449*0a6a1f1dSLionel Sambuc }
1450*0a6a1f1dSLionel Sambuc 
test_warn_chained_if_stmts_6(int x)1451*0a6a1f1dSLionel Sambuc void test_warn_chained_if_stmts_6(int x) {
1452*0a6a1f1dSLionel Sambuc   if (x == 1)
1453*0a6a1f1dSLionel Sambuc     ;
1454*0a6a1f1dSLionel Sambuc   else if (x == 2)
1455*0a6a1f1dSLionel Sambuc     ;
1456*0a6a1f1dSLionel Sambuc   else if (x == 2) // expected-warning {{expression is identical to previous condition}}
1457*0a6a1f1dSLionel Sambuc     ;
1458*0a6a1f1dSLionel Sambuc   else if (x == 3)
1459*0a6a1f1dSLionel Sambuc     ;
1460*0a6a1f1dSLionel Sambuc }
1461*0a6a1f1dSLionel Sambuc 
test_warn_chained_if_stmts_7(int x)1462*0a6a1f1dSLionel Sambuc void test_warn_chained_if_stmts_7(int x) {
1463*0a6a1f1dSLionel Sambuc   if (x == 1)
1464*0a6a1f1dSLionel Sambuc     ;
1465*0a6a1f1dSLionel Sambuc   else if (x == 2)
1466*0a6a1f1dSLionel Sambuc     ;
1467*0a6a1f1dSLionel Sambuc   else if (x == 3)
1468*0a6a1f1dSLionel Sambuc     ;
1469*0a6a1f1dSLionel Sambuc   else if (x == 2) // expected-warning {{expression is identical to previous condition}}
1470*0a6a1f1dSLionel Sambuc     ;
1471*0a6a1f1dSLionel Sambuc   else if (x == 5)
1472*0a6a1f1dSLionel Sambuc     ;
1473*0a6a1f1dSLionel Sambuc }
1474*0a6a1f1dSLionel Sambuc 
test_warn_chained_if_stmts_8(int x)1475*0a6a1f1dSLionel Sambuc void test_warn_chained_if_stmts_8(int x) {
1476*0a6a1f1dSLionel Sambuc   if (x == 1)
1477*0a6a1f1dSLionel Sambuc     ;
1478*0a6a1f1dSLionel Sambuc   else if (x == 2)
1479*0a6a1f1dSLionel Sambuc     ;
1480*0a6a1f1dSLionel Sambuc   else if (x == 3)
1481*0a6a1f1dSLionel Sambuc     ;
1482*0a6a1f1dSLionel Sambuc   else if (x == 2) // expected-warning {{expression is identical to previous condition}}
1483*0a6a1f1dSLionel Sambuc     ;
1484*0a6a1f1dSLionel Sambuc   else if (x == 5)
1485*0a6a1f1dSLionel Sambuc     ;
1486*0a6a1f1dSLionel Sambuc   else if (x == 3) // expected-warning {{expression is identical to previous condition}}
1487*0a6a1f1dSLionel Sambuc     ;
1488*0a6a1f1dSLionel Sambuc   else if (x == 7)
1489*0a6a1f1dSLionel Sambuc     ;
1490*0a6a1f1dSLionel Sambuc }
1491*0a6a1f1dSLionel Sambuc 
test_nowarn_chained_if_stmts_1(int x)1492*0a6a1f1dSLionel Sambuc void test_nowarn_chained_if_stmts_1(int x) {
1493*0a6a1f1dSLionel Sambuc   if (func())
1494*0a6a1f1dSLionel Sambuc     ;
1495*0a6a1f1dSLionel Sambuc   else if (func()) // no-warning
1496*0a6a1f1dSLionel Sambuc     ;
1497*0a6a1f1dSLionel Sambuc }
1498*0a6a1f1dSLionel Sambuc 
test_nowarn_chained_if_stmts_2(int x)1499*0a6a1f1dSLionel Sambuc void test_nowarn_chained_if_stmts_2(int x) {
1500*0a6a1f1dSLionel Sambuc   if (func())
1501*0a6a1f1dSLionel Sambuc     ;
1502*0a6a1f1dSLionel Sambuc   else if (x == 1)
1503*0a6a1f1dSLionel Sambuc     ;
1504*0a6a1f1dSLionel Sambuc   else if (func()) // no-warning
1505*0a6a1f1dSLionel Sambuc     ;
1506*0a6a1f1dSLionel Sambuc }
1507*0a6a1f1dSLionel Sambuc 
test_nowarn_chained_if_stmts_3(int x)1508*0a6a1f1dSLionel Sambuc void test_nowarn_chained_if_stmts_3(int x) {
1509*0a6a1f1dSLionel Sambuc   if (x++)
1510*0a6a1f1dSLionel Sambuc     ;
1511*0a6a1f1dSLionel Sambuc   else if (x++) // no-warning
1512*0a6a1f1dSLionel Sambuc     ;
1513*0a6a1f1dSLionel Sambuc }
1514*0a6a1f1dSLionel Sambuc 
test_warn_wchar()1515*0a6a1f1dSLionel Sambuc void test_warn_wchar() {
1516*0a6a1f1dSLionel Sambuc   const wchar_t * a = 0 ? L"Warning" : L"Warning"; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
1517*0a6a1f1dSLionel Sambuc }
test_nowarn_wchar()1518*0a6a1f1dSLionel Sambuc void test_nowarn_wchar() {
1519*0a6a1f1dSLionel Sambuc   const wchar_t * a = 0 ? L"No" : L"Warning";
1520*0a6a1f1dSLionel Sambuc }
1521*0a6a1f1dSLionel Sambuc 
test_nowarn_long()1522*0a6a1f1dSLionel Sambuc void test_nowarn_long() {
1523*0a6a1f1dSLionel Sambuc   int a = 0, b = 0;
1524*0a6a1f1dSLionel Sambuc   long c;
1525*0a6a1f1dSLionel Sambuc   if (0) {
1526*0a6a1f1dSLionel Sambuc     b -= a;
1527*0a6a1f1dSLionel Sambuc     c = 0;
1528*0a6a1f1dSLionel Sambuc   } else { // no-warning
1529*0a6a1f1dSLionel Sambuc     b -= a;
1530*0a6a1f1dSLionel Sambuc     c = 0LL;
1531*0a6a1f1dSLionel Sambuc   }
1532*0a6a1f1dSLionel Sambuc }
1533