[llvm] MathExtras: avoid unnecessarily widening types (PR #95426)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 26 02:03:02 PDT 2024
================
@@ -189,21 +189,37 @@ TEST(MathExtras, AlignTo) {
EXPECT_EQ(8u, alignTo(5, 8));
EXPECT_EQ(24u, alignTo(17, 8));
EXPECT_EQ(0u, alignTo(~0LL, 8));
- EXPECT_EQ(static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1,
- alignTo(std::numeric_limits<uint32_t>::max(), 2));
+ EXPECT_EQ(8u, alignTo(5ULL, 8ULL));
+ EXPECT_EQ(254u,
+ alignTo(static_cast<uint8_t>(200), static_cast<uint8_t>(127)));
----------------
jayfoad wrote:
I don't think this test is doing anything useful. The point of it was to show that the old implementation `(Value + Align - 1) / Align * Align` would go wrong if `Value + Align` overflowed 2^bitwidth. But that would not happen in this case because integral promotion would widen the argument to int before doing the add.
https://github.com/llvm/llvm-project/pull/95426
More information about the llvm-commits
mailing list