| 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s |
| 2 | // rdar://12202422 |
| 3 | |
| 4 | int value(void); |
| 5 | |
| 6 | int main() |
| 7 | { |
| 8 | int a = value(); |
| 9 | |
| 10 | if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} |
| 11 | return 0; |
| 12 | if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} |
| 13 | return 0; |
| 14 | if (a < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} |
| 15 | return 0; |
| 16 | if (a <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} |
| 17 | return 0; |
| 18 | if (a > 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} |
| 19 | return 0; |
| 20 | if (a >= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} |
| 21 | return 0; |
| 22 | |
| 23 | if (0x1234567812345678L == a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} |
| 24 | return 0; |
| 25 | if (0x1234567812345678L != a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} |
| 26 | return 0; |
| 27 | if (0x1234567812345678L < a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} |
| 28 | return 0; |
| 29 | if (0x1234567812345678L <= a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} |
| 30 | return 0; |
| 31 | if (0x1234567812345678L > a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} |
| 32 | return 0; |
| 33 | if (0x1234567812345678L >= a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} |
| 34 | return 0; |
| 35 | if (a == 0x1234567812345678LL) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} |
| 36 | return 0; |
| 37 | if (a == -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} |
| 38 | return 0; |
| 39 | if (a < -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} |
| 40 | return 0; |
| 41 | if (a > -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always true}} |
| 42 | return 0; |
| 43 | if (a <= -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} |
| 44 | return 0; |
| 45 | if (a >= -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always true}} |
| 46 | return 0; |
| 47 | |
| 48 | |
| 49 | if (a == 0x12345678L) // no warning |
| 50 | return 1; |
| 51 | |
| 52 | short s = value(); |
| 53 | if (s == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} |
| 54 | return 0; |
| 55 | if (s != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} |
| 56 | return 0; |
| 57 | if (s < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} |
| 58 | return 0; |
| 59 | if (s <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} |
| 60 | return 0; |
| 61 | if (s > 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} |
| 62 | return 0; |
| 63 | if (s >= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} |
| 64 | return 0; |
| 65 | |
| 66 | if (0x1234567812345678L == s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} |
| 67 | return 0; |
| 68 | if (0x1234567812345678L != s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} |
| 69 | return 0; |
| 70 | if (0x1234567812345678L < s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} |
| 71 | return 0; |
| 72 | if (0x1234567812345678L <= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} |
| 73 | return 0; |
| 74 | if (0x1234567812345678L > s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} |
| 75 | return 0; |
| 76 | if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} |
| 77 | return 0; |
| 78 | |
| 79 | long l = value(); |
| 80 | if (l == 0x1234567812345678L) |
| 81 | return 0; |
| 82 | if (l != 0x1234567812345678L) |
| 83 | return 0; |
| 84 | if (l < 0x1234567812345678L) |
| 85 | return 0; |
| 86 | if (l <= 0x1234567812345678L) |
| 87 | return 0; |
| 88 | if (l > 0x1234567812345678L) |
| 89 | return 0; |
| 90 | if (l >= 0x1234567812345678L) |
| 91 | return 0; |
| 92 | |
| 93 | if (0x1234567812345678L == l) |
| 94 | return 0; |
| 95 | if (0x1234567812345678L != l) |
| 96 | return 0; |
| 97 | if (0x1234567812345678L < l) |
| 98 | return 0; |
| 99 | if (0x1234567812345678L <= l) |
| 100 | return 0; |
| 101 | if (0x1234567812345678L > l) |
| 102 | return 0; |
| 103 | if (0x1234567812345678L >= l) |
| 104 | return 0; |
| 105 | |
| 106 | enum E { |
| 107 | yes, |
| 108 | no, |
| 109 | maybe |
| 110 | }; |
| 111 | enum E e; |
| 112 | |
| 113 | if (e == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'enum E' is always false}} |
| 114 | return 0; |
| 115 | |
| 116 | return 1; |
| 117 | } |
| 118 | |