reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
//===-- alignment.cpp -------------------------------------------*- C++ -*-===//
//
// 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 "gwp_asan/tests/harness.h"

TEST_F(DefaultGuardedPoolAllocator, BasicAllocation) {
  std::vector<std::pair<int, int>> AllocSizeToAlignment = {
      {1, 1},   {2, 2},   {3, 4},       {4, 4},       {5, 8},   {7, 8},
      {8, 8},   {9, 16},  {15, 16},     {16, 16},     {17, 16}, {31, 16},
      {32, 16}, {33, 16}, {4095, 4096}, {4096, 4096},
  };

  for (const auto &KV : AllocSizeToAlignment) {
    void *Ptr = GPA.allocate(KV.first);
    EXPECT_NE(nullptr, Ptr);

    // Check the alignment of the pointer is as expected.
    EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(Ptr) % KV.second);

    GPA.deallocate(Ptr);
  }
}