[Alignment] Remove alignTo version taking a MaybeAlign

This commit is contained in:
Guillaume Chatelet 2022-06-20 15:02:59 +00:00
parent 589c8d6fb9
commit d3cf49e984
3 changed files with 4 additions and 19 deletions

View File

@ -184,12 +184,6 @@ inline uint64_t alignTo(uint64_t Size, Align A, uint64_t Skew) {
return alignTo(Size - Skew, A) + Skew;
}
/// Returns a multiple of A needed to store `Size` bytes.
/// Returns `Size` if current alignment is undefined.
inline uint64_t alignTo(uint64_t Size, MaybeAlign A) {
return A ? alignTo(Size, A.getValue()) : Size;
}
/// Aligns `Addr` to `Alignment` bytes, rounding up.
inline uintptr_t alignAddr(const void *Addr, Align Alignment) {
uintptr_t ArithAddr = reinterpret_cast<uintptr_t>(Addr);

View File

@ -648,7 +648,7 @@ STATISTIC(ObjectVisitorLoad,
APInt ObjectSizeOffsetVisitor::align(APInt Size, MaybeAlign Alignment) {
if (Options.RoundToAlign && Alignment)
return APInt(IntTyBits, alignTo(Size.getZExtValue(), Alignment));
return APInt(IntTyBits, alignTo(Size.getZExtValue(), *Alignment));
return Size;
}

View File

@ -93,11 +93,7 @@ TEST(AlignmentTest, AlignTo) {
return reinterpret_cast<const void *>(offset);
}
} kTests[] = {
// MaybeAlign
{0, 0, 0},
{0, 1, 1},
{0, 5, 5},
// MaybeAlign / Align
// Align
{1, 0, 0},
{1, 1, 1},
{1, 5, 5},
@ -112,14 +108,9 @@ TEST(AlignmentTest, AlignTo) {
{4, 6, 8},
};
for (const auto &T : kTests) {
MaybeAlign A(T.alignment);
// Test MaybeAlign
Align A = Align(T.alignment);
EXPECT_EQ(alignTo(T.offset, A), T.rounded);
// Test Align
if (A) {
EXPECT_EQ(alignTo(T.offset, A.getValue()), T.rounded);
EXPECT_EQ(alignAddr(T.forgedAddr(), A.getValue()), T.rounded);
}
EXPECT_EQ(alignAddr(T.forgedAddr(), A), T.rounded);
}
}