summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/MathExtrasTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/MathExtrasTest.cpp')
-rw-r--r--llvm/unittests/Support/MathExtrasTest.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/unittests/Support/MathExtrasTest.cpp b/llvm/unittests/Support/MathExtrasTest.cpp
index 8bd47e34c7e..0f3854680ac 100644
--- a/llvm/unittests/Support/MathExtrasTest.cpp
+++ b/llvm/unittests/Support/MathExtrasTest.cpp
@@ -190,4 +190,21 @@ TEST(MathExtras, RoundUpToAlignment) {
EXPECT_EQ(552u, RoundUpToAlignment(321, 255, 42));
}
+template<typename T>
+void SaturatingAddTestHelper()
+{
+ const T Max = std::numeric_limits<T>::max();
+ EXPECT_EQ(T(3), SaturatingAdd(T(1), T(2)));
+ EXPECT_EQ(Max, SaturatingAdd(Max, T(1)));
+ EXPECT_EQ(Max, SaturatingAdd(T(1), Max));
+ EXPECT_EQ(Max, SaturatingAdd(Max, Max));
+}
+
+TEST(MathExtras, SaturatingAdd) {
+ SaturatingAddTestHelper<uint8_t>();
+ SaturatingAddTestHelper<uint16_t>();
+ SaturatingAddTestHelper<uint32_t>();
+ SaturatingAddTestHelper<uint64_t>();
+}
+
}
OpenPOWER on IntegriCloud