llvm/llvm/unittests/Support/AlignmentTest.cpp

//=== - llvm/unittest/Support/Alignment.cpp - Alignment utility tests -----===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/Support/Alignment.h"
#include "llvm/ADT/STLExtras.h"
#include "gtest/gtest.h"

#include <vector>

#ifdef _MSC_VER
// Disable warnings about potential divide by 0.
#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) {}

// Death tests reply on assert which is disabled in release mode.
#ifndef NDEBUG

// We use a subset of valid alignments for DEATH_TESTs as they are particularly
// slow.
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 // NDEBUG

} // end anonymous namespace

#ifdef _MSC_VER
#pragma warning(pop)
#endif