xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/bool-compare.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc 
f(int x,int y,int z)4*0a6a1f1dSLionel Sambuc void f(int x, int y, int z) {
5*0a6a1f1dSLionel Sambuc   int a,b;
6*0a6a1f1dSLionel Sambuc 
7*0a6a1f1dSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc   if ((a > 2) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
9*0a6a1f1dSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc   if (a > b)      {} // no warning
11*0a6a1f1dSLionel Sambuc   if (a < b)      {} // no warning
12*0a6a1f1dSLionel Sambuc   if (a >= b)     {} // no warning
13*0a6a1f1dSLionel Sambuc   if (a <= b)     {} // no warning
14*0a6a1f1dSLionel Sambuc   if (a == b)     {} // no warning
15*0a6a1f1dSLionel Sambuc   if (a != b)     {} // no warning
16*0a6a1f1dSLionel Sambuc 
17*0a6a1f1dSLionel Sambuc   if (a > 0) {} // no warning
18*0a6a1f1dSLionel Sambuc   if (a > 1) {} // no warning
19*0a6a1f1dSLionel Sambuc   if (a > 2) {} // no warning
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc   if (a >= 0) {} // no warning
22*0a6a1f1dSLionel Sambuc   if (a >= 1) {} // no warning
23*0a6a1f1dSLionel Sambuc   if (a >= 2) {} // no warning
24*0a6a1f1dSLionel Sambuc   if (a >= -1) {} // no warning
25*0a6a1f1dSLionel Sambuc 
26*0a6a1f1dSLionel Sambuc   if (a <= 0) {} // no warning
27*0a6a1f1dSLionel Sambuc   if (a <= 1) {} // no warning
28*0a6a1f1dSLionel Sambuc   if (a <= 2) {} // no warning
29*0a6a1f1dSLionel Sambuc   if (a <= -1) {} // no warning
30*0a6a1f1dSLionel Sambuc 
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc   if (!a > 0) {}  // no warning
33*0a6a1f1dSLionel Sambuc   if (!a > 1)     {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
34*0a6a1f1dSLionel Sambuc   if (!a > 2)     {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
35*0a6a1f1dSLionel Sambuc   if (!a > y)     {} // no warning
36*0a6a1f1dSLionel Sambuc   if (!a > b)     {} // no warning
37*0a6a1f1dSLionel Sambuc   if (!a > -1)    {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
38*0a6a1f1dSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc   if (!a < 0)     {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
40*0a6a1f1dSLionel Sambuc   if (!a < 1)     {} // no warning
41*0a6a1f1dSLionel Sambuc   if (!a < 2)     {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
42*0a6a1f1dSLionel Sambuc   if (!a < y)     {} // no warning
43*0a6a1f1dSLionel Sambuc   if (!a < b)     {} // no warning
44*0a6a1f1dSLionel Sambuc   if (!a < -1)    {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
45*0a6a1f1dSLionel Sambuc 
46*0a6a1f1dSLionel Sambuc   if (!a >= 0)    {} // expected-warning {{comparison of constant 0 with boolean expression is always true}}
47*0a6a1f1dSLionel Sambuc   if (!a >= 1)    {} // no warning
48*0a6a1f1dSLionel Sambuc   if (!a >= 2)    {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
49*0a6a1f1dSLionel Sambuc   if (!a >= y)    {} // no warning
50*0a6a1f1dSLionel Sambuc   if (!a >= b)    {} // no warning
51*0a6a1f1dSLionel Sambuc   if (!a >= -1)   {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
52*0a6a1f1dSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc   if (!a <= 0)    {} // no warning
54*0a6a1f1dSLionel Sambuc   if (!a <= 1)    {} // expected-warning {{comparison of constant 1 with boolean expression is always true}}
55*0a6a1f1dSLionel Sambuc   if (!a <= 2)    {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
56*0a6a1f1dSLionel Sambuc   if (!a <= y)    {} // no warning
57*0a6a1f1dSLionel Sambuc   if (!a <= b)    {} // no warning
58*0a6a1f1dSLionel Sambuc   if (!a <= -1)   {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
59*0a6a1f1dSLionel Sambuc 
60*0a6a1f1dSLionel Sambuc   if ((a||b) > 0) {} // no warning
61*0a6a1f1dSLionel Sambuc   if ((a||b) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
62*0a6a1f1dSLionel Sambuc   if ((a||b) > 4) {} // expected-warning {{comparison of constant 4 with boolean expression is always false}}
63*0a6a1f1dSLionel Sambuc   if ((a||b) > -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always true}}
64*0a6a1f1dSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc   if ((a&&b) > 0) {} // no warning
66*0a6a1f1dSLionel Sambuc   if ((a&&b) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
67*0a6a1f1dSLionel Sambuc   if ((a&&b) > 4) {} // expected-warning {{comparison of constant 4 with boolean expression is always false}}
68*0a6a1f1dSLionel Sambuc 
69*0a6a1f1dSLionel Sambuc   if ((a<y) > 0)  {} // no warning
70*0a6a1f1dSLionel Sambuc   if ((a<y) > 1)  {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
71*0a6a1f1dSLionel Sambuc   if ((a<y) > 4)  {} // expected-warning {{comparison of constant 4 with boolean expression is always false}}
72*0a6a1f1dSLionel Sambuc   if ((a<y) > z)  {} // no warning
73*0a6a1f1dSLionel Sambuc   if ((a<y) > -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
74*0a6a1f1dSLionel Sambuc 
75*0a6a1f1dSLionel Sambuc   if ((a<y) == 0) {} // no warning
76*0a6a1f1dSLionel Sambuc   if ((a<y) == 1) {} // no warning
77*0a6a1f1dSLionel Sambuc   if ((a<y) == 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
78*0a6a1f1dSLionel Sambuc   if ((a<y) == z) {} // no warning
79*0a6a1f1dSLionel Sambuc   if ((a<y) == -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always false}}
80*0a6a1f1dSLionel Sambuc 
81*0a6a1f1dSLionel Sambuc   if ((a<y) != 0) {} // no warning
82*0a6a1f1dSLionel Sambuc   if ((a<y) != 1) {} // no warning
83*0a6a1f1dSLionel Sambuc   if ((a<y) != 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
84*0a6a1f1dSLionel Sambuc   if ((a<y) != z) {} // no warning
85*0a6a1f1dSLionel Sambuc   if ((a<y) != -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always true}}
86*0a6a1f1dSLionel Sambuc 
87*0a6a1f1dSLionel Sambuc   if ((a<y) == z) {} // no warning
88*0a6a1f1dSLionel Sambuc   if (a>y<z)      {} // no warning
89*0a6a1f1dSLionel Sambuc   if ((a<y) > z)  {} // no warning
90*0a6a1f1dSLionel Sambuc   if((a<y)>(z<y)) {} // no warning
91*0a6a1f1dSLionel Sambuc   if((a<y)==(z<y)){} // no warning
92*0a6a1f1dSLionel Sambuc   if((a<y)!=(z<y)){} // no warning
93*0a6a1f1dSLionel Sambuc   if((z==x)<(y==z)){}// no warning
94*0a6a1f1dSLionel Sambuc   if((a<y)!=((z==x)<(y==z))){} //no warning
95*0a6a1f1dSLionel Sambuc 
96*0a6a1f1dSLionel Sambuc 
97*0a6a1f1dSLionel Sambuc   if (0 > !a)     {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
98*0a6a1f1dSLionel Sambuc   if (1 > !a)     {} // no warning
99*0a6a1f1dSLionel Sambuc   if (2 > !a)     {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
100*0a6a1f1dSLionel Sambuc   if (y > !a)     {} // no warning
101*0a6a1f1dSLionel Sambuc   if (-1 > !a)    {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
102*0a6a1f1dSLionel Sambuc 
103*0a6a1f1dSLionel Sambuc   if (0 < !a)     {} // no warning
104*0a6a1f1dSLionel Sambuc   if (1 < !a)     {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
105*0a6a1f1dSLionel Sambuc   if (2 < !a)     {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
106*0a6a1f1dSLionel Sambuc   if (y < !a)     {} // no warning
107*0a6a1f1dSLionel Sambuc   if (-1 < !a)    {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
108*0a6a1f1dSLionel Sambuc 
109*0a6a1f1dSLionel Sambuc   if (0 >= !a)    {} // no warning
110*0a6a1f1dSLionel Sambuc   if (1 >= !a)    {} // expected-warning {{comparison of constant 1 with boolean expression is always true}}
111*0a6a1f1dSLionel Sambuc   if (2 >= !a)    {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
112*0a6a1f1dSLionel Sambuc   if (y >= !a)    {} // no warning
113*0a6a1f1dSLionel Sambuc   if (-1 >= !a)   {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
114*0a6a1f1dSLionel Sambuc 
115*0a6a1f1dSLionel Sambuc   if (0 <= !a)    {} // expected-warning {{comparison of constant 0 with boolean expression is always true}}
116*0a6a1f1dSLionel Sambuc   if (1 <= !a)    {} // no warning
117*0a6a1f1dSLionel Sambuc   if (2 <= !a)    {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
118*0a6a1f1dSLionel Sambuc   if (y <= !a)    {} // no warning
119*0a6a1f1dSLionel Sambuc   if (-1 <= !a)   {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
120*0a6a1f1dSLionel Sambuc 
121*0a6a1f1dSLionel Sambuc   if (0 > (a||b)) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
122*0a6a1f1dSLionel Sambuc   if (1 > (a||b)) {} // no warning
123*0a6a1f1dSLionel Sambuc   if (4 > (a||b)) {} // expected-warning {{comparison of constant 4 with boolean expression is always true}}
124*0a6a1f1dSLionel Sambuc 
125*0a6a1f1dSLionel Sambuc   if (0 > (a&&b)) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
126*0a6a1f1dSLionel Sambuc   if (1 > (a&&b)) {} // no warning
127*0a6a1f1dSLionel Sambuc   if (4 > (a&&b)) {} // expected-warning {{comparison of constant 4 with boolean expression is always true}}
128*0a6a1f1dSLionel Sambuc 
129*0a6a1f1dSLionel Sambuc   if (0 > (a<y))  {} // expected-warning {{comparison of constant 0 with boolean expression is always false}}
130*0a6a1f1dSLionel Sambuc   if (1 > (a<y))  {} // no warning
131*0a6a1f1dSLionel Sambuc   if (4 > (a<y))  {} // expected-warning {{comparison of constant 4 with boolean expression is always true}}
132*0a6a1f1dSLionel Sambuc   if (z > (a<y))  {} // no warning
133*0a6a1f1dSLionel Sambuc   if (-1 > (a<y)) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
134*0a6a1f1dSLionel Sambuc 
135*0a6a1f1dSLionel Sambuc   if (0 == (a<y)) {} // no warning
136*0a6a1f1dSLionel Sambuc   if (1 == (a<y)) {} // no warning
137*0a6a1f1dSLionel Sambuc   if (2 == (a<y)) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
138*0a6a1f1dSLionel Sambuc   if (z == (a<y)) {} // no warning
139*0a6a1f1dSLionel Sambuc   if (-1 == (a<y)){} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
140*0a6a1f1dSLionel Sambuc 
141*0a6a1f1dSLionel Sambuc   if (0 !=(a<y))  {} // no warning
142*0a6a1f1dSLionel Sambuc   if (1 !=(a<y))  {} // no warning
143*0a6a1f1dSLionel Sambuc   if (2 !=(a<y))  {} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
144*0a6a1f1dSLionel Sambuc   if (z !=(a<y))  {} // no warning
145*0a6a1f1dSLionel Sambuc   if (-1 !=(a<y)) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
146*0a6a1f1dSLionel Sambuc 
147*0a6a1f1dSLionel Sambuc   if (z ==(a<y))  {}    // no warning
148*0a6a1f1dSLionel Sambuc   if (z<a>y)      {}        // no warning
149*0a6a1f1dSLionel Sambuc   if (z > (a<y))  {}    // no warning
150*0a6a1f1dSLionel Sambuc   if((z<y)>(a<y)) {}   // no warning
151*0a6a1f1dSLionel Sambuc   if((z<y)==(a<y)){}  // no warning
152*0a6a1f1dSLionel Sambuc   if((z<y)!=(a<y)){}  // no warning
153*0a6a1f1dSLionel Sambuc   if((y==z)<(z==x)){}  // no warning
154*0a6a1f1dSLionel Sambuc   if(((z==x)<(y==z))!=(a<y)){}  // no warning
155*0a6a1f1dSLionel Sambuc 
156*0a6a1f1dSLionel Sambuc   if(((z==x)<(-1==z))!=(a<y)){} // no warning
157*0a6a1f1dSLionel Sambuc   if(((z==x)<(z==-1))!=(a<y)){} // no warning
158*0a6a1f1dSLionel Sambuc   if(((z==x)<-1)!=(a<y)){} // expected-warning {{comparison of constant -1 with boolean expression is always false}}
159*0a6a1f1dSLionel Sambuc   if(((z==x)< 2)!=(a<y)){} // expected-warning {{comparison of constant 2 with boolean expression is always true}}
160*0a6a1f1dSLionel Sambuc   if(((z==x)<(z>2))!=(a<y)){} // no warning
161*0a6a1f1dSLionel Sambuc 
162*0a6a1f1dSLionel Sambuc }
163