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
main()6 int main()
7 {
8 int a = value();
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 long l = value();
78 if (l == 0x1234567812345678L)
79 return 0;
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
91 if (0x1234567812345678L == l)
92 return 0;
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
104 unsigned un = 0;
105 if (un == 0x0000000000000000L)
106 return 0;
107 if (un != 0x0000000000000000L)
108 return 0;
109 if (un < 0x0000000000000000L)
110 return 0;
111 if (un <= 0x0000000000000000L)
112 return 0;
113 if (un > 0x0000000000000000L)
114 return 0;
115 if (un >= 0x0000000000000000L)
116 return 0;
117
118 if (0x0000000000000000L == un)
119 return 0;
120 if (0x0000000000000000L != un)
121 return 0;
122 if (0x0000000000000000L < un)
123 return 0;
124 if (0x0000000000000000L <= un)
125 return 0;
126 if (0x0000000000000000L > un)
127 return 0;
128 if (0x0000000000000000L >= un)
129 return 0;
130 float fl = 0;
131 if (fl == 0x0000000000000000L) // no warning
132 return 0;
133
134 float dl = 0;
135 if (dl == 0x0000000000000000L) // no warning
136 return 0;
137
138 enum E {
139 yes,
140 no,
141 maybe
142 };
143 enum E e;
144
145 if (e == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'enum E' is always false}}
146 return 0;
147
148 return 1;
149 }
150