blob: 4b1637c46c5e32a541ff32f865e884ffba4bb4cb [file] [log] [blame]
Fariborz Jahanian15a93562012-09-18 17:37:21 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s
2// rdar://12202422
3
4int value(void);
5
6int main()
7{
8 int a = value();
Fariborz Jahaniana193f202012-09-20 19:36:41 +00009 if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000010 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000011 if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000012 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000013 if (a < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000014 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000015 if (a <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000016 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000017 if (a > 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000018 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000019 if (a >= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000020 return 0;
21
Fariborz Jahaniana193f202012-09-20 19:36:41 +000022 if (0x1234567812345678L == a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000023 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000024 if (0x1234567812345678L != a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000025 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000026 if (0x1234567812345678L < a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000027 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000028 if (0x1234567812345678L <= a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000029 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000030 if (0x1234567812345678L > a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000031 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000032 if (0x1234567812345678L >= a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000033 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000034 if (a == 0x1234567812345678LL) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000035 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000036 if (a == -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000037 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000038 if (a < -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000039 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000040 if (a > -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000041 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000042 if (a <= -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000043 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000044 if (a >= -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000045 return 0;
46
47
48 if (a == 0x12345678L) // no warning
49 return 1;
50
51 short s = value();
Fariborz Jahaniana193f202012-09-20 19:36:41 +000052 if (s == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000053 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000054 if (s != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000055 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000056 if (s < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000057 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000058 if (s <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000059 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000060 if (s > 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000061 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000062 if (s >= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000063 return 0;
64
Fariborz Jahaniana193f202012-09-20 19:36:41 +000065 if (0x1234567812345678L == s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000066 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000067 if (0x1234567812345678L != s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000068 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000069 if (0x1234567812345678L < s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000070 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000071 if (0x1234567812345678L <= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000072 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000073 if (0x1234567812345678L > s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000074 return 0;
Fariborz Jahaniana193f202012-09-20 19:36:41 +000075 if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +000076 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
Fariborz Jahaniana193f202012-09-20 19:36:41 +0000145 if (e == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'enum E' is always false}}
Fariborz Jahanian15a93562012-09-18 17:37:21 +0000146 return 0;
147
148 return 1;
149}