| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-bitwise-compare %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify -Wall -Wno-unused %s |
| 3 |
|
| 4 |
#define mydefine 2 |
| 5 |
#define mydefine2 -2 |
| 6 |
|
| 7 |
enum { |
| 8 |
ZERO, |
| 9 |
ONE, |
| 10 |
}; |
| 11 |
|
| 12 |
void f(int x) { |
| 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}} |
| 17 |
|
| 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}} |
| 22 |
|
| 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}} |
| 26 |
|
| 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}} |
| 30 |
|
| 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}} |
| 33 |
|
| 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}} |
| 36 |
|
| 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}} |
| 39 |
|
| 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}} |
| 44 |
|
| 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}} |
| 48 |
|
| 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}} |
| 51 |
|
| 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}} |
| 54 |
|
| 55 |
if ((x & 8) == 8) {} |
| 56 |
if ((x & 8) != 8) {} |
| 57 |
if ((x | 4) == 4) {} |
| 58 |
if ((x | 4) != 4) {} |
| 59 |
|
| 60 |
if ((x | 4) == +4) {} |
| 61 |
if ((x | 4) != +4) {} |
| 62 |
|
| 63 |
if ((x & 1) == !12) {} |
| 64 |
if ((x | 0) == !0) {} |
| 65 |
|
| 66 |
if ((x | 1) == ~4) {} |
| 67 |
if ((x | 1) != ~0) {} |
| 68 |
|
| 69 |
if ((-2 & x) != 4) {} |
| 70 |
if ((x & -8) == -8) {} |
| 71 |
if ((x & -8) != -8) {} |
| 72 |
if ((x | -4) == -4) {} |
| 73 |
if ((x | -4) != -4) {} |
| 74 |
|
| 75 |
if ((x & 9) == 8) {} |
| 76 |
if ((x & 9) != 8) {} |
| 77 |
if ((x | 4) == 5) {} |
| 78 |
if ((x | 4) != 5) {} |
| 79 |
|
| 80 |
if ((x & -9) == -10) {} |
| 81 |
if ((x & -9) != -10) {} |
| 82 |
if ((x | -4) == -3) {} |
| 83 |
if ((x | -4) != -3) {} |
| 84 |
|
| 85 |
if ((x^0) == 0) {} |
| 86 |
|
| 87 |
if ((x & mydefine) == 8) {} |
| 88 |
if ((x | mydefine) == 4) {} |
| 89 |
|
| 90 |
if ((x & mydefine2) == 8) {} |
| 91 |
if ((x | mydefine2) == 4) {} |
| 92 |
|
| 93 |
if ((x & 1) == 1L) {} |
| 94 |
|
| 95 |
if (0 != (x | !0LL)) {} // expected-warning {{bitwise comparison always evaluates to true}} |
| 96 |
} |
| 97 |
|
| 98 |
void g(int x) { |
| 99 |
if (x | 5) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}} |
| 100 |
if (5 | x) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}} |
| 101 |
if (!((x | 5))) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}} |
| 102 |
|
| 103 |
if (x | -1) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}} |
| 104 |
if (x | ONE) {} // expected-warning {{bitwise or with non-zero value always evaluates to true}} |
| 105 |
|
| 106 |
if (x | ZERO) {} |
| 107 |
} |