From 869a3344f17975f57a328dcc8bacf6775344c045 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 17 Oct 2007 21:10:21 +0000 Subject: [PATCH] Added member template functions to MallocAllocator and BumpPtrAllocator that implement allocations that return a properly typed pointer. For BumpPtrAllocator, the allocated memory is automatically aligned to the minimum alignment of the type (as calculated by llvm::AlignOf::Alignment). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43087 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Allocator.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h index f23a41f17fa..397cf0c7c2e 100644 --- a/include/llvm/Support/Allocator.h +++ b/include/llvm/Support/Allocator.h @@ -14,6 +14,7 @@ #ifndef LLVM_SUPPORT_ALLOCATOR_H #define LLVM_SUPPORT_ALLOCATOR_H +#include "llvm/Support/AlignOf.h" #include namespace llvm { @@ -25,6 +26,10 @@ public: void Reset() {} void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); } + + template + T* Allocate() { return reinterpret_cast(malloc(sizeof(T))); } + void Deallocate(void *Ptr) { free(Ptr); } void PrintStats() const {} }; @@ -41,6 +46,13 @@ public: void Reset(); void *Allocate(unsigned Size, unsigned Alignment); + + template + T* Allocate() { + return reinterpret_cast(Allocate(sizeof(T),AlignOf::Alignment)); + } + + void Deallocate(void *Ptr) {} void PrintStats() const; }; -- 2.34.1