#include "llvm/Support/Alignment.h"
#include "llvm/ADT/STLExtras.h"
#include "gtest/gtest.h"
#include <vector>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4723)
#endif
usingnamespacellvm;
namespace {
TEST(AlignmentTest, AlignOfConstant) { … }
TEST(AlignmentTest, AlignConstant) { … }
TEST(AlignmentTest, AlignConstexprConstant) { … }
std::vector<uint64_t> getValidAlignments() { … }
TEST(AlignmentTest, AlignDefaultCTor) { … }
TEST(AlignmentTest, MaybeAlignDefaultCTor) { … }
TEST(AlignmentTest, ValidCTors) { … }
TEST(AlignmentTest, CheckMaybeAlignHasValue) { … }
TEST(AlignmentTest, Division) { … }
TEST(AlignmentTest, AlignTo) { … }
TEST(AlignmentTest, AlignToWithSkew) { … }
TEST(AlignmentTest, Log2) { … }
TEST(AlignmentTest, Encode_Decode) { … }
TEST(AlignmentTest, isAligned_isAddrAligned) { … }
TEST(AlignmentTest, offsetToAlignment) { … }
TEST(AlignmentTest, AlignComparisons) { … }
TEST(AlignmentTest, AssumeAligned) { … }
#ifndef NDEBUG
std::vector<uint64_t> getValidAlignmentsForDeathTest() {
return {1, 1ULL << 31, 1ULL << 63};
}
std::vector<uint64_t> getNonPowerOfTwo() { return {3, 10, 15}; }
TEST(AlignmentDeathTest, InvalidCTors) {
EXPECT_DEATH((Align(0)), "Value must not be 0");
for (uint64_t Value : getNonPowerOfTwo()) {
EXPECT_DEATH((Align(Value)), "Alignment is not a power of 2");
EXPECT_DEATH((MaybeAlign(Value)),
"Alignment is neither 0 nor a power of 2");
}
}
TEST(AlignmentDeathTest, ComparisonsWithZero) {
for (uint64_t Value : getValidAlignmentsForDeathTest()) {
EXPECT_DEATH((void)(Align(Value) == 0), ".* should be defined");
EXPECT_DEATH((void)(Align(Value) != 0), ".* should be defined");
EXPECT_DEATH((void)(Align(Value) >= 0), ".* should be defined");
EXPECT_DEATH((void)(Align(Value) <= 0), ".* should be defined");
EXPECT_DEATH((void)(Align(Value) > 0), ".* should be defined");
EXPECT_DEATH((void)(Align(Value) < 0), ".* should be defined");
}
}
TEST(AlignmentDeathTest, AlignAddr) {
const void *const unaligned_high_ptr =
reinterpret_cast<const void *>(std::numeric_limits<uintptr_t>::max() - 1);
EXPECT_DEATH(alignAddr(unaligned_high_ptr, Align(16)), "Overflow");
}
#endif
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif