llvm.org GIT mirror llvm / 8142ce5
convert all the constant range EXPECT_EQ tests to use EXPECT_TRUE since ConstantRange doesn't have an std::ostream inserter anymore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79831 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 129 addition(s) and 128 deletion(s). Raw diff Collapse all Expand all
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/Support/ConstantRange.h"
10 #include "llvm/Support/raw_ostream.h"
1011
1112 #include "gtest/gtest.h"
1213
7778 }
7879
7980 TEST_F(ConstantRangeTest, Equality) {
80 EXPECT_EQ(Full, Full);
81 EXPECT_EQ(Empty, Empty);
82 EXPECT_EQ(One, One);
83 EXPECT_EQ(Some, Some);
84 EXPECT_EQ(Wrap, Wrap);
85 EXPECT_NE(Full, Empty);
86 EXPECT_NE(Full, One);
87 EXPECT_NE(Full, Some);
88 EXPECT_NE(Full, Wrap);
89 EXPECT_NE(Empty, One);
90 EXPECT_NE(Empty, Some);
91 EXPECT_NE(Empty, Wrap);
92 EXPECT_NE(One, Some);
93 EXPECT_NE(One, Wrap);
94 EXPECT_NE(Some, Wrap);
81 EXPECT_TRUE(Full == Full);
82 EXPECT_TRUE(Empty == Empty);
83 EXPECT_TRUE(One == One);
84 EXPECT_TRUE(Some == Some);
85 EXPECT_TRUE(Wrap == Wrap);
86 EXPECT_TRUE(Full != Empty);
87 EXPECT_TRUE(Full != One);
88 EXPECT_TRUE(Full != Some);
89 EXPECT_TRUE(Full != Wrap);
90 EXPECT_TRUE(Empty != One);
91 EXPECT_TRUE(Empty != Some);
92 EXPECT_TRUE(Empty != Wrap);
93 EXPECT_TRUE(One != Some);
94 EXPECT_TRUE(One != Wrap);
95 EXPECT_TRUE(Some != Wrap);
9596 }
9697
9798 TEST_F(ConstantRangeTest, SingleElement) {
150151 ConstantRange TWrap = Wrap.truncate(10);
151152 EXPECT_TRUE(TFull.isFullSet());
152153 EXPECT_TRUE(TEmpty.isEmptySet());
153 EXPECT_EQ(TOne, ConstantRange(APInt(One.getLower()).trunc(10),
154 EXPECT_TRUE(TOne == ConstantRange(APInt(One.getLower()).trunc(10),
154155 APInt(One.getUpper()).trunc(10)));
155156 EXPECT_TRUE(TSome.isFullSet());
156157 }
161162 ConstantRange ZOne = One.zeroExtend(20);
162163 ConstantRange ZSome = Some.zeroExtend(20);
163164 ConstantRange ZWrap = Wrap.zeroExtend(20);
164 EXPECT_EQ(ZFull, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
165 EXPECT_TRUE(ZFull == ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
165166 EXPECT_TRUE(ZEmpty.isEmptySet());
166 EXPECT_EQ(ZOne, ConstantRange(APInt(One.getLower()).zext(20),
167 APInt(One.getUpper()).zext(20)));
168 EXPECT_EQ(ZSome, ConstantRange(APInt(Some.getLower()).zext(20),
169 APInt(Some.getUpper()).zext(20)));
170 EXPECT_EQ(ZWrap, ConstantRange(APInt(Wrap.getLower()).zext(20),
171 APInt(Wrap.getUpper()).zext(20)));
167 EXPECT_TRUE(ZOne == ConstantRange(APInt(One.getLower()).zext(20),
168 APInt(One.getUpper()).zext(20)));
169 EXPECT_TRUE(ZSome == ConstantRange(APInt(Some.getLower()).zext(20),
170 APInt(Some.getUpper()).zext(20)));
171 EXPECT_TRUE(ZWrap == ConstantRange(APInt(Wrap.getLower()).zext(20),
172 APInt(Wrap.getUpper()).zext(20)));
172173 }
173174
174175 TEST_F(ConstantRangeTest, SExt) {
177178 ConstantRange SOne = One.signExtend(20);
178179 ConstantRange SSome = Some.signExtend(20);
179180 ConstantRange SWrap = Wrap.signExtend(20);
180 EXPECT_EQ(SFull, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
181 APInt(20, INT16_MAX + 1, true)));
181 EXPECT_TRUE(SFull == ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
182 APInt(20, INT16_MAX + 1, true)));
182183 EXPECT_TRUE(SEmpty.isEmptySet());
183 EXPECT_EQ(SOne, ConstantRange(APInt(One.getLower()).sext(20),
184 APInt(One.getUpper()).sext(20)));
185 EXPECT_EQ(SSome, ConstantRange(APInt(Some.getLower()).sext(20),
186 APInt(Some.getUpper()).sext(20)));
187 EXPECT_EQ(SWrap, ConstantRange(APInt(Wrap.getLower()).sext(20),
188 APInt(Wrap.getUpper()).sext(20)));
184 EXPECT_TRUE(SOne == ConstantRange(APInt(One.getLower()).sext(20),
185 APInt(One.getUpper()).sext(20)));
186 EXPECT_TRUE(SSome == ConstantRange(APInt(Some.getLower()).sext(20),
187 APInt(Some.getUpper()).sext(20)));
188 EXPECT_TRUE(SWrap == ConstantRange(APInt(Wrap.getLower()).sext(20),
189 APInt(Wrap.getUpper()).sext(20)));
189190 }
190191
191192 TEST_F(ConstantRangeTest, IntersectWith) {
201202 EXPECT_TRUE(Full.intersectWith(Some) == Some);
202203 EXPECT_TRUE(Some.intersectWith(Wrap).isEmptySet());
203204 EXPECT_TRUE(One.intersectWith(Wrap).isEmptySet());
204 EXPECT_EQ(One.intersectWith(Wrap), Wrap.intersectWith(One));
205 EXPECT_TRUE(One.intersectWith(Wrap) == Wrap.intersectWith(One));
205206
206207 // Klee generated testcase from PR4545.
207208 // The intersection of i16 [4, 2) and [6, 5) is disjoint, looking like
208209 // 01..4.6789ABCDEF where the dots represent values not in the intersection.
209210 ConstantRange LHS(APInt(16, 4), APInt(16, 2));
210211 ConstantRange RHS(APInt(16, 6), APInt(16, 5));
211 EXPECT_EQ(LHS.intersectWith(RHS), LHS);
212 EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
212213 }
213214
214215 TEST_F(ConstantRangeTest, UnionWith) {
215 EXPECT_EQ(Wrap.unionWith(One),
216 ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
217 EXPECT_EQ(One.unionWith(Wrap), Wrap.unionWith(One));
216 EXPECT_TRUE(Wrap.unionWith(One) ==
217 ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
218 EXPECT_TRUE(One.unionWith(Wrap) == Wrap.unionWith(One));
218219 EXPECT_TRUE(Empty.unionWith(Empty).isEmptySet());
219220 EXPECT_TRUE(Full.unionWith(Full).isFullSet());
220221 EXPECT_TRUE(Some.unionWith(Wrap).isFullSet());
221222
222223 // PR4545
223 EXPECT_EQ(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
224 ConstantRange(APInt(16, 0), APInt(16, 8))),
225 ConstantRange(APInt(16, 14), APInt(16, 8)));
226 EXPECT_EQ(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
227 ConstantRange(APInt(16, 4), APInt(16, 0))),
228 ConstantRange(16));
229 EXPECT_EQ(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
230 ConstantRange(APInt(16, 2), APInt(16, 1))),
231 ConstantRange(16));
224 EXPECT_TRUE(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
225 ConstantRange(APInt(16, 0), APInt(16, 8))) ==
226 ConstantRange(APInt(16, 14), APInt(16, 8)));
227 EXPECT_TRUE(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
228 ConstantRange(APInt(16, 4), APInt(16, 0))) ==
229 ConstantRange(16));
230 EXPECT_TRUE(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
231 ConstantRange(APInt(16, 2), APInt(16, 1))) ==
232 ConstantRange(16));
232233 }
233234
234235 TEST_F(ConstantRangeTest, SubtractAPInt) {
235236 EXPECT_TRUE(Full.subtract(APInt(16, 4)).isFullSet());
236237 EXPECT_TRUE(Empty.subtract(APInt(16, 4)).isEmptySet());
237 EXPECT_EQ(Some.subtract(APInt(16, 4)),
238 ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
239 EXPECT_EQ(Wrap.subtract(APInt(16, 4)),
240 ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
241 EXPECT_EQ(One.subtract(APInt(16, 4)),
242 ConstantRange(APInt(16, 0x6)));
238 EXPECT_TRUE(Some.subtract(APInt(16, 4)) ==
239 ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
240 EXPECT_TRUE(Wrap.subtract(APInt(16, 4)) ==
241 ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
242 EXPECT_TRUE(One.subtract(APInt(16, 4)) ==
243 ConstantRange(APInt(16, 0x6)));
243244 }
244245
245246 TEST_F(ConstantRangeTest, Add) {
246247 EXPECT_TRUE(Full.add(APInt(16, 4)).isFullSet());
247 EXPECT_EQ(Full.add(Full), Full);
248 EXPECT_EQ(Full.add(Empty), Empty);
249 EXPECT_EQ(Full.add(One), Full);
250 EXPECT_EQ(Full.add(Some), Full);
251 EXPECT_EQ(Full.add(Wrap), Full);
252 EXPECT_EQ(Empty.add(Empty), Empty);
253 EXPECT_EQ(Empty.add(One), Empty);
254 EXPECT_EQ(Empty.add(Some), Empty);
255 EXPECT_EQ(Empty.add(Wrap), Empty);
248 EXPECT_TRUE(Full.add(Full) == Full);
249 EXPECT_TRUE(Full.add(Empty) == Empty);
250 EXPECT_TRUE(Full.add(One) == Full);
251 EXPECT_TRUE(Full.add(Some) == Full);
252 EXPECT_TRUE(Full.add(Wrap) == Full);
253 EXPECT_TRUE(Empty.add(Empty) == Empty);
254 EXPECT_TRUE(Empty.add(One) == Empty);
255 EXPECT_TRUE(Empty.add(Some) == Empty);
256 EXPECT_TRUE(Empty.add(Wrap) == Empty);
256257 EXPECT_TRUE(Empty.add(APInt(16, 4)).isEmptySet());
257 EXPECT_EQ(Some.add(APInt(16, 4)),
258 ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
259 EXPECT_EQ(Wrap.add(APInt(16, 4)),
260 ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
261 EXPECT_EQ(One.add(APInt(16, 4)),
262 ConstantRange(APInt(16, 0xe)));
258 EXPECT_TRUE(Some.add(APInt(16, 4)) ==
259 ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
260 EXPECT_TRUE(Wrap.add(APInt(16, 4)) ==
261 ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
262 EXPECT_TRUE(One.add(APInt(16, 4)) ==
263 ConstantRange(APInt(16, 0xe)));
263264 }
264265
265266 TEST_F(ConstantRangeTest, Multiply) {
266 EXPECT_EQ(Full.multiply(Full), Full);
267 EXPECT_EQ(Full.multiply(Empty), Empty);
268 EXPECT_EQ(Full.multiply(One), Full);
269 EXPECT_EQ(Full.multiply(Some), Full);
270 EXPECT_EQ(Full.multiply(Wrap), Full);
271 EXPECT_EQ(Empty.multiply(Empty), Empty);
272 EXPECT_EQ(Empty.multiply(One), Empty);
273 EXPECT_EQ(Empty.multiply(Some), Empty);
274 EXPECT_EQ(Empty.multiply(Wrap), Empty);
275 EXPECT_EQ(One.multiply(One), ConstantRange(APInt(16, 0xa*0xa),
276 APInt(16, 0xa*0xa + 1)));
277 EXPECT_EQ(One.multiply(Some), ConstantRange(APInt(16, 0xa*0xa),
278 APInt(16, 0xa*0xaa9 + 1)));
267 EXPECT_TRUE(Full.multiply(Full) == Full);
268 EXPECT_TRUE(Full.multiply(Empty) == Empty);
269 EXPECT_TRUE(Full.multiply(One) == Full);
270 EXPECT_TRUE(Full.multiply(Some) == Full);
271 EXPECT_TRUE(Full.multiply(Wrap) == Full);
272 EXPECT_TRUE(Empty.multiply(Empty) == Empty);
273 EXPECT_TRUE(Empty.multiply(One) == Empty);
274 EXPECT_TRUE(Empty.multiply(Some) == Empty);
275 EXPECT_TRUE(Empty.multiply(Wrap) == Empty);
276 EXPECT_TRUE(One.multiply(One) == ConstantRange(APInt(16, 0xa*0xa),
277 APInt(16, 0xa*0xa + 1)));
278 EXPECT_TRUE(One.multiply(Some) == ConstantRange(APInt(16, 0xa*0xa),
279 APInt(16, 0xa*0xaa9 + 1)));
279280 EXPECT_TRUE(One.multiply(Wrap).isFullSet());
280281 EXPECT_TRUE(Some.multiply(Some).isFullSet());
281 EXPECT_EQ(Some.multiply(Wrap), Full);
282 EXPECT_EQ(Wrap.multiply(Wrap), Full);
282 EXPECT_TRUE(Some.multiply(Wrap) == Full);
283 EXPECT_TRUE(Wrap.multiply(Wrap) == Full);
283284
284285 // http://llvm.org/PR4545
285 EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
286 ConstantRange(APInt(4, 6), APInt(4, 2))),
287 ConstantRange(4, /*isFullSet=*/true));
286 EXPECT_TRUE(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
287 ConstantRange(APInt(4, 6), APInt(4, 2))) ==
288 ConstantRange(4, /*isFullSet=*/true));
288289 }
289290
290291 TEST_F(ConstantRangeTest, UMax) {
291292 EXPECT_TRUE(Full.umax(Full).isFullSet());
292293 EXPECT_TRUE(Full.umax(Empty).isEmptySet());
293 EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
294 EXPECT_TRUE(Full.umax(Some) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
294295 EXPECT_TRUE(Full.umax(Wrap).isFullSet());
295 EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
296 EXPECT_EQ(Empty.umax(Empty), Empty);
297 EXPECT_EQ(Empty.umax(Some), Empty);
298 EXPECT_EQ(Empty.umax(Wrap), Empty);
299 EXPECT_EQ(Empty.umax(One), Empty);
300 EXPECT_EQ(Some.umax(Some), Some);
301 EXPECT_EQ(Some.umax(Wrap), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
302 EXPECT_EQ(Some.umax(One), Some);
296 EXPECT_TRUE(Full.umax(Some) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
297 EXPECT_TRUE(Empty.umax(Empty) == Empty);
298 EXPECT_TRUE(Empty.umax(Some) == Empty);
299 EXPECT_TRUE(Empty.umax(Wrap) == Empty);
300 EXPECT_TRUE(Empty.umax(One) == Empty);
301 EXPECT_TRUE(Some.umax(Some) == Some);
302 EXPECT_TRUE(Some.umax(Wrap) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
303 EXPECT_TRUE(Some.umax(One) == Some);
303304 // TODO: ConstantRange is currently over-conservative here.
304 EXPECT_EQ(Wrap.umax(Wrap), Full);
305 EXPECT_EQ(Wrap.umax(One), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
306 EXPECT_EQ(One.umax(One), One);
305 EXPECT_TRUE(Wrap.umax(Wrap) == Full);
306 EXPECT_TRUE(Wrap.umax(One) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
307 EXPECT_TRUE(One.umax(One) == One);
307308 }
308309
309310 TEST_F(ConstantRangeTest, SMax) {
310311 EXPECT_TRUE(Full.smax(Full).isFullSet());
311312 EXPECT_TRUE(Full.smax(Empty).isEmptySet());
312 EXPECT_EQ(Full.smax(Some), ConstantRange(APInt(16, 0xa),
313 APInt::getSignedMinValue(16)));
313 EXPECT_TRUE(Full.smax(Some) == ConstantRange(APInt(16, 0xa),
314 APInt::getSignedMinValue(16)));
314315 EXPECT_TRUE(Full.smax(Wrap).isFullSet());
315 EXPECT_EQ(Full.smax(One), ConstantRange(APInt(16, 0xa),
316 APInt::getSignedMinValue(16)));
317 EXPECT_EQ(Empty.smax(Empty), Empty);
318 EXPECT_EQ(Empty.smax(Some), Empty);
319 EXPECT_EQ(Empty.smax(Wrap), Empty);
320 EXPECT_EQ(Empty.smax(One), Empty);
321 EXPECT_EQ(Some.smax(Some), Some);
322 EXPECT_EQ(Some.smax(Wrap), ConstantRange(APInt(16, 0xa),
323 APInt(16, (uint64_t)INT16_MIN)));
324 EXPECT_EQ(Some.smax(One), Some);
325 EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa),
326 APInt(16, (uint64_t)INT16_MIN)));
327 EXPECT_EQ(One.smax(One), One);
316 EXPECT_TRUE(Full.smax(One) == ConstantRange(APInt(16, 0xa),
317 APInt::getSignedMinValue(16)));
318 EXPECT_TRUE(Empty.smax(Empty) == Empty);
319 EXPECT_TRUE(Empty.smax(Some) == Empty);
320 EXPECT_TRUE(Empty.smax(Wrap) == Empty);
321 EXPECT_TRUE(Empty.smax(One) == Empty);
322 EXPECT_TRUE(Some.smax(Some) == Some);
323 EXPECT_TRUE(Some.smax(Wrap) == ConstantRange(APInt(16, 0xa),
324 APInt(16, (uint64_t)INT16_MIN)));
325 EXPECT_TRUE(Some.smax(One) == Some);
326 EXPECT_TRUE(Wrap.smax(One) == ConstantRange(APInt(16, 0xa),
327 APInt(16, (uint64_t)INT16_MIN)));
328 EXPECT_TRUE(One.smax(One) == One);
328329 }
329330
330331 TEST_F(ConstantRangeTest, UDiv) {
331 EXPECT_EQ(Full.udiv(Full), Full);
332 EXPECT_EQ(Full.udiv(Empty), Empty);
333 EXPECT_EQ(Full.udiv(One), ConstantRange(APInt(16, 0),
334 APInt(16, 0xffff / 0xa + 1)));
335 EXPECT_EQ(Full.udiv(Some), ConstantRange(APInt(16, 0),
336 APInt(16, 0xffff / 0xa + 1)));
337 EXPECT_EQ(Full.udiv(Wrap), Full);
338 EXPECT_EQ(Empty.udiv(Empty), Empty);
339 EXPECT_EQ(Empty.udiv(One), Empty);
340 EXPECT_EQ(Empty.udiv(Some), Empty);
341 EXPECT_EQ(Empty.udiv(Wrap), Empty);
342 EXPECT_EQ(One.udiv(One), ConstantRange(APInt(16, 1)));
343 EXPECT_EQ(One.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 2)));
344 EXPECT_EQ(One.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
345 EXPECT_EQ(Some.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 0x111)));
346 EXPECT_EQ(Some.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
347 EXPECT_EQ(Wrap.udiv(Wrap), Full);
332 EXPECT_TRUE(Full.udiv(Full) == Full);
333 EXPECT_TRUE(Full.udiv(Empty) == Empty);
334 EXPECT_TRUE(Full.udiv(One) == ConstantRange(APInt(16, 0),
335 APInt(16, 0xffff / 0xa + 1)));
336 EXPECT_TRUE(Full.udiv(Some) == ConstantRange(APInt(16, 0),
337 APInt(16, 0xffff / 0xa + 1)));
338 EXPECT_TRUE(Full.udiv(Wrap) == Full);
339 EXPECT_TRUE(Empty.udiv(Empty) == Empty);
340 EXPECT_TRUE(Empty.udiv(One) == Empty);
341 EXPECT_TRUE(Empty.udiv(Some) == Empty);
342 EXPECT_TRUE(Empty.udiv(Wrap) == Empty);
343 EXPECT_TRUE(One.udiv(One) == ConstantRange(APInt(16, 1)));
344 EXPECT_TRUE(One.udiv(Some) == ConstantRange(APInt(16, 0), APInt(16, 2)));
345 EXPECT_TRUE(One.udiv(Wrap) == ConstantRange(APInt(16, 0), APInt(16, 0xb)));
346 EXPECT_TRUE(Some.udiv(Some) == ConstantRange(APInt(16, 0), APInt(16, 0x111)));
347 EXPECT_TRUE(Some.udiv(Wrap) == ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
348 EXPECT_TRUE(Wrap.udiv(Wrap) == Full);
348349 }
349350
350351 } // anonymous namespace