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