Overhaul of Stmt allocation:
- Made allocation of Stmt objects using vanilla new/delete a *compiler
error* by making this new/delete "protected" within class Stmt.
- Now the only way to allocate Stmt objects is by using the new
operator that takes ASTContext& as an argument. This ensures that
all Stmt nodes are allocated from the same (pool) allocator.
- Naturally, these two changes required that *all* creation sites for
AST nodes use new (ASTContext&). This is a large patch, but the
majority of the changes are just this mechanical adjustment.
- The above changes also mean that AST nodes can no longer be
deallocated using 'delete'. Instead, one most do
StmtObject->Destroy(ASTContext&) or do
ASTContextObject.Deallocate(StmtObject) (the latter not running the
'Destroy' method).
Along the way I also...
- Made CompoundStmt allocate its array of Stmt* using the allocator in
ASTContext (previously it used std::vector). There are a whole
bunch of other Stmt classes that need to be similarly changed to
ensure that all memory allocated for ASTs comes from the allocator
in ASTContext.
- Added a new smart pointer ExprOwningPtr to Sema.h. This replaces
the uses of llvm::OwningPtr within Sema, as llvm::OwningPtr used
'delete' to free memory instead of a Stmt's 'Destroy' method.
Big thanks to Doug Gregor for helping with the acrobatics of making
'new/delete' private and the new smart pointer ExprOwningPtr!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63997 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaNamedCast.cpp b/lib/Sema/SemaNamedCast.cpp
index e2137b3..c5bee98 100644
--- a/lib/Sema/SemaNamedCast.cpp
+++ b/lib/Sema/SemaNamedCast.cpp
@@ -76,26 +76,26 @@
case tok::kw_const_cast:
if (!TypeDependent)
CheckConstCast(*this, Ex, DestType, OpRange, DestRange);
- return new CXXConstCastExpr(DestType.getNonReferenceType(), Ex,
- DestType, OpLoc);
+ return new (Context) CXXConstCastExpr(DestType.getNonReferenceType(), Ex,
+ DestType, OpLoc);
case tok::kw_dynamic_cast:
if (!TypeDependent)
CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange);
- return new CXXDynamicCastExpr(DestType.getNonReferenceType(), Ex,
- DestType, OpLoc);
+ return new (Context)CXXDynamicCastExpr(DestType.getNonReferenceType(), Ex,
+ DestType, OpLoc);
case tok::kw_reinterpret_cast:
if (!TypeDependent)
CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
- return new CXXReinterpretCastExpr(DestType.getNonReferenceType(), Ex,
- DestType, OpLoc);
+ return new (Context) CXXReinterpretCastExpr(DestType.getNonReferenceType(),
+ Ex, DestType, OpLoc);
case tok::kw_static_cast:
if (!TypeDependent)
CheckStaticCast(*this, Ex, DestType, OpRange);
- return new CXXStaticCastExpr(DestType.getNonReferenceType(), Ex,
- DestType, OpLoc);
+ return new (Context) CXXStaticCastExpr(DestType.getNonReferenceType(), Ex,
+ DestType, OpLoc);
}
return true;