brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 6adc9ab Raw
39 lines · cpp
1//===- MemAlloc.cpp - Memory allocation functions -------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/Support/MemAlloc.h"10#include <new>11 12// These are out of line to have __cpp_aligned_new not affect ABI.13 14LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *15llvm::allocate_buffer(size_t Size, size_t Alignment) {16  void *Result = ::operator new(Size,17#ifdef __cpp_aligned_new18                                std::align_val_t(Alignment),19#endif20                                std::nothrow);21  if (Result == nullptr) {22    report_bad_alloc_error("Buffer allocation failed");23  }24  return Result;25}26 27void llvm::deallocate_buffer(void *Ptr, size_t Size, size_t Alignment) {28  ::operator delete(Ptr29#ifdef __cpp_sized_deallocation30                    ,31                    Size32#endif33#ifdef __cpp_aligned_new34                    ,35                    std::align_val_t(Alignment)36#endif37  );38}39