From: Benjamin Kramer Date: Tue, 4 Aug 2015 12:34:23 +0000 (+0000) Subject: [ASTContext] Add a templated convenience wrapper for Allocate. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7406a25aa29fa53623b15ad41c195ce46727427;p=clang [ASTContext] Add a templated convenience wrapper for Allocate. This brings ASTContext closer to LLVM's Allocator concept. Ideally we would just derive ASTContext from llvm::AllocatorBase, but that does not work because ASTContext's allocator is mutable and we allocate using const ASTContext& everywhere. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243972 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index c67fa67ab6..dc9bc29d8d 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -501,6 +501,9 @@ public: void *Allocate(size_t Size, unsigned Align = 8) const { return BumpAlloc.Allocate(Size, Align); } + template T *Allocate(size_t Num = 1) const { + return static_cast(Allocate(Num * sizeof(T), llvm::alignOf())); + } void Deallocate(void *Ptr) const { } /// Return the total amount of physical memory allocated for representing diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 771aeefda7..46dce32287 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -724,7 +724,7 @@ MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, } static StringRef copyIntoContext(const ASTContext &C, StringRef str) { - return str.copy(C.getAllocator()); + return str.copy(C); } void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,