LLVM 21.0.0git
MemAlloc.cpp
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include <new>
11
12// These are out of line to have __cpp_aligned_new not affect ABI.
13
15llvm::allocate_buffer(size_t Size, size_t Alignment) {
16 void *Result = ::operator new(Size,
17#ifdef __cpp_aligned_new
18 std::align_val_t(Alignment),
19#endif
20 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(Ptr
29#ifdef __cpp_sized_deallocation
30 ,
31 Size
32#endif
33#ifdef __cpp_aligned_new
34 ,
35 std::align_val_t(Alignment)
36#endif
37 );
38}
#define LLVM_ATTRIBUTE_RETURNS_NOALIAS
\macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a pointer that does not al...
Definition: Compiler.h:375
#define LLVM_ATTRIBUTE_RETURNS_NONNULL
Definition: Compiler.h:357
uint64_t Size
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * allocate_buffer(size_t Size, size_t Alignment)
Allocate a buffer of memory with the given size and alignment.
Definition: MemAlloc.cpp:15
void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment)
Deallocate a buffer of memory with the given size and alignment.
Definition: MemAlloc.cpp:27
void report_bad_alloc_error(const char *Reason, bool GenCrashDiag=true)
Reports a bad alloc error, calling any user defined bad alloc error handler.