1 // RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-bitwise-compare %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -Wno-unused %s
13 if ((8 & x
) == 3) {} // expected-warning {{bitwise comparison always evaluates to false}}
14 if ((x
& 8) == 4) {} // expected-warning {{bitwise comparison always evaluates to false}}
15 if ((-8 & x
) == 3) {} // expected-warning {{bitwise comparison always evaluates to false}}
16 if ((x
& -8) == 4) {} // expected-warning {{bitwise comparison always evaluates to false}}
18 if ((x
& 8) != 4) {} // expected-warning {{bitwise comparison always evaluates to true}}
19 if ((2 & x
) != 4) {} // expected-warning {{bitwise comparison always evaluates to true}}
20 if ((x
& -8) != 4) {} // expected-warning {{bitwise comparison always evaluates to true}}
21 if ((-2 & x
) != 3) {} // expected-warning {{bitwise comparison always evaluates to true}}
23 if ((x
| 4) == 3) {} // expected-warning {{bitwise comparison always evaluates to false}}
24 if ((x
| 3) != 4) {} // expected-warning {{bitwise comparison always evaluates to true}}
25 if ((5 | x
) != 3) {} // expected-warning {{bitwise comparison always evaluates to true}}
27 if ((x
| -4) == 3) {} // expected-warning {{bitwise comparison always evaluates to false}}
28 if ((x
| -3) != 4) {} // expected-warning {{bitwise comparison always evaluates to true}}
29 if ((-5 | x
) != 3) {} // expected-warning {{bitwise comparison always evaluates to true}}
31 if ((x
& 0x15) == 0x13) {} // expected-warning {{bitwise comparison always evaluates to false}}
32 if ((x
& 0xFFEB) == 0x13) {} // expected-warning {{bitwise comparison always evaluates to false}}
34 if ((0x23 | x
) == 0x155){} // expected-warning {{bitwise comparison always evaluates to false}}
35 if ((0xFFDD | x
) == 0x155){} // expected-warning {{bitwise comparison always evaluates to false}}
37 if (!!((8 & x
) == 3)) {} // expected-warning {{bitwise comparison always evaluates to false}}
38 if (!!((-8 & x
) == 3)) {} // expected-warning {{bitwise comparison always evaluates to false}}
40 int y
= ((8 & x
) == 3) ? 1 : 2; // expected-warning {{bitwise comparison always evaluates to false}}
41 y
= ((-8 & x
) == 3) ? 1 : 2; // expected-warning {{bitwise comparison always evaluates to false}}
42 y
= ((3 | x
) != 5) ? 1 : 2; // expected-warning {{bitwise comparison always evaluates to true}}
43 y
= ((-3 | x
) != 5) ? 1 : 2; // expected-warning {{bitwise comparison always evaluates to true}}
45 if ((x
& 0) != !0) {} // expected-warning {{bitwise comparison always evaluates to true}}
46 if ((x
& 0) == !0) {} // expected-warning {{bitwise comparison always evaluates to false}}
47 if ((x
& 2) == !0) {} // expected-warning {{bitwise comparison always evaluates to false}}
49 if ((x
| 4) == +3) {} // expected-warning {{bitwise comparison always evaluates to false}}
50 if ((x
| 3) != +4) {} // expected-warning {{bitwise comparison always evaluates to true}}
52 if ((x
& 8) != ~4) {} // expected-warning {{bitwise comparison always evaluates to true}}
53 if ((x
& 0) == ~4) {} // expected-warning {{bitwise comparison always evaluates to false}}
63 if ((x
& 1) == !12) {}
70 if ((x
& -8) == -8) {}
71 if ((x
& -8) != -8) {}
72 if ((x
| -4) == -4) {}
73 if ((x
| -4) != -4) {}
80 if ((x
& -9) == -10) {}
81 if ((x
& -9) != -10) {}
82 if ((x
| -4) == -3) {}
83 if ((x
| -4) != -3) {}
87 if ((x
& mydefine
) == 8) {}
88 if ((x
| mydefine
) == 4) {}
90 if ((x
& mydefine2
) == 8) {}
91 if ((x
| mydefine2
) == 4) {}
97 if (x
| 5) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}}
98 if (5 | x
) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}}
99 if (!((x
| 5))) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}}
101 if (x
| -1) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}}
102 if (x
| ONE
) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}}