aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/MathExtrasTest.cpp
diff options
context:
space:
mode:
authorRamkumar Ramachandra <ramkumar.ramachandra@codasip.com>2024-08-19 16:03:42 +0100
committerGitHub <noreply@github.com>2024-08-19 16:03:42 +0100
commit7dd6340bdadf86bd0facdea89d1876a5c36dc33b (patch)
tree836344561bea762d36c283ec731ffba4cb4f3266 /llvm/unittests/Support/MathExtrasTest.cpp
parenta566635915730e6720e1b341f014c7c62af748bf (diff)
downloadllvm-7dd6340bdadf86bd0facdea89d1876a5c36dc33b.zip
llvm-7dd6340bdadf86bd0facdea89d1876a5c36dc33b.tar.gz
llvm-7dd6340bdadf86bd0facdea89d1876a5c36dc33b.tar.bz2
MathExtras: template'ize alignToPowerOf2 (#97814)
Follow up on 5627794 (MathExtras: avoid unnecessarily widening types) to change the overflow behavior of alignToPowerOf2 to only overflow if the result is not representable in the return type. This allows us to template'ize it, and avoid unnecessarily widening the types of arguments.
Diffstat (limited to 'llvm/unittests/Support/MathExtrasTest.cpp')
-rw-r--r--llvm/unittests/Support/MathExtrasTest.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/unittests/Support/MathExtrasTest.cpp b/llvm/unittests/Support/MathExtrasTest.cpp
index a1cc609..984185f 100644
--- a/llvm/unittests/Support/MathExtrasTest.cpp
+++ b/llvm/unittests/Support/MathExtrasTest.cpp
@@ -218,8 +218,11 @@ TEST(MathExtras, AlignToPowerOf2) {
EXPECT_EQ(24u, alignToPowerOf2(17, 8));
EXPECT_EQ(0u, alignToPowerOf2(~0LL, 8));
EXPECT_EQ(240u, alignToPowerOf2(240, 16));
- EXPECT_EQ(static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1,
- alignToPowerOf2(std::numeric_limits<uint32_t>::max(), 2));
+
+ // Overflow.
+ EXPECT_EQ(0u, alignToPowerOf2(static_cast<uint8_t>(200),
+ static_cast<uint8_t>(128)));
+ EXPECT_EQ(0u, alignToPowerOf2(std::numeric_limits<uint32_t>::max(), 2));
}
TEST(MathExtras, AlignDown) {