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