alignment.cpp revision 1.1.1.1
1//===-- alignment.cpp -------------------------------------------*- C++ -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#include "gwp_asan/tests/harness.h" 10 11TEST_F(DefaultGuardedPoolAllocator, BasicAllocation) { 12 std::vector<std::pair<int, int>> AllocSizeToAlignment = { 13 {1, 1}, {2, 2}, {3, 4}, {4, 4}, {5, 8}, {7, 8}, 14 {8, 8}, {9, 16}, {15, 16}, {16, 16}, {17, 16}, {31, 16}, 15 {32, 16}, {33, 16}, {4095, 4096}, {4096, 4096}, 16 }; 17 18 for (const auto &KV : AllocSizeToAlignment) { 19 void *Ptr = GPA.allocate(KV.first); 20 EXPECT_NE(nullptr, Ptr); 21 22 // Check the alignment of the pointer is as expected. 23 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(Ptr) % KV.second); 24 25 GPA.deallocate(Ptr); 26 } 27} 28