diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:46:15 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:46:15 +0000 |
commit | dd58ef019b700900793a1eb48b52123db01b654e (patch) | |
tree | fcfbb4df56a744f4ddc6122c50521dd3f1c5e196 /unittests/IR/ConstantRangeTest.cpp | |
parent | 2fe5752e3a7c345cdb59e869278d36af33c13fa4 (diff) |
Notes
Diffstat (limited to 'unittests/IR/ConstantRangeTest.cpp')
-rw-r--r-- | unittests/IR/ConstantRangeTest.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp index de4eec4abf5d..1f32eea3e43b 100644 --- a/unittests/IR/ConstantRangeTest.cpp +++ b/unittests/IR/ConstantRangeTest.cpp @@ -9,6 +9,7 @@ #include "llvm/IR/ConstantRange.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/Operator.h" #include "gtest/gtest.h" using namespace llvm; @@ -568,4 +569,55 @@ TEST(ConstantRange, MakeSatisfyingICmpRegion) { ConstantRange(APInt(8, 4), APInt(8, -128))); } +TEST(ConstantRange, MakeOverflowingRegion) { + const int IntMin4Bits = 8; + const int IntMax4Bits = 7; + typedef OverflowingBinaryOperator OBO; + + for (int Const : {0, -1, -2, 1, 2, IntMin4Bits, IntMax4Bits}) { + APInt C(4, Const, true /* = isSigned */); + + auto NUWRegion = + ConstantRange::makeNoWrapRegion(Instruction::Add, C, OBO::NoUnsignedWrap); + + EXPECT_FALSE(NUWRegion.isEmptySet()); + + auto NSWRegion = + ConstantRange::makeNoWrapRegion(Instruction::Add, C, OBO::NoSignedWrap); + + EXPECT_FALSE(NSWRegion.isEmptySet()); + + auto NoWrapRegion = ConstantRange::makeNoWrapRegion( + Instruction::Add, C, OBO::NoSignedWrap | OBO::NoUnsignedWrap); + + EXPECT_FALSE(NoWrapRegion.isEmptySet()); + EXPECT_TRUE(NUWRegion.intersectWith(NSWRegion).contains(NoWrapRegion)); + + for (APInt I = NUWRegion.getLower(), E = NUWRegion.getUpper(); I != E; + ++I) { + bool Overflow = false; + I.uadd_ov(C, Overflow); + EXPECT_FALSE(Overflow); + } + + for (APInt I = NSWRegion.getLower(), E = NSWRegion.getUpper(); I != E; + ++I) { + bool Overflow = false; + I.sadd_ov(C, Overflow); + EXPECT_FALSE(Overflow); + } + + for (APInt I = NoWrapRegion.getLower(), E = NoWrapRegion.getUpper(); I != E; + ++I) { + bool Overflow = false; + + I.sadd_ov(C, Overflow); + EXPECT_FALSE(Overflow); + + I.uadd_ov(C, Overflow); + EXPECT_FALSE(Overflow); + } + } +} + } // anonymous namespace |