summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-02-07 01:47:29 +0000
committerTed Kremenek <kremenek@apple.com>2009-02-07 01:47:29 +0000
commit5a201951cafa73ca51fc58c4a380b4f0cab38676 (patch)
tree74c8aa1764c05d4ef05fc85de0e3c9581bcd31fa /clang/lib/Sema/SemaExpr.cpp
parent773ca057b10ae87c05d9f5206e24ee07d3ed4f70 (diff)
downloadbcm5719-llvm-5a201951cafa73ca51fc58c4a380b4f0cab38676.tar.gz
bcm5719-llvm-5a201951cafa73ca51fc58c4a380b4f0cab38676.zip
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! llvm-svn: 63997
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 201a0f99e33..8ce8bfdd8ba 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -454,8 +454,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
if (BaseObject) {
// BaseObject is an anonymous struct/union variable (and is,
// therefore, not part of another non-anonymous record).
- delete BaseObjectExpr;
-
+ if (BaseObjectExpr) BaseObjectExpr->Destroy(Context);
BaseObjectExpr = new (Context) DeclRefExpr(BaseObject,BaseObject->getType(),
SourceLocation());
ExtraQuals
@@ -1770,7 +1769,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
<< Fn->getType()->isBlockPointerType() << Fn->getSourceRange();
// Use default arguments for missing arguments
NumArgsToCheck = NumArgsInProto;
- Call->setNumArgs(NumArgsInProto);
+ Call->setNumArgs(Context, NumArgsInProto);
}
// If too many are passed and not variadic, error on the extras and drop
@@ -1783,7 +1782,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
<< SourceRange(Args[NumArgsInProto]->getLocStart(),
Args[NumArgs-1]->getLocEnd());
// This deletes the extra arguments.
- Call->setNumArgs(NumArgsInProto);
+ Call->setNumArgs(Context, NumArgsInProto);
Invalid = true;
}
NumArgsToCheck = NumArgsInProto;
@@ -1945,7 +1944,7 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc,
// of arguments and function on error.
// FIXME: Except that llvm::OwningPtr uses delete, when it really must be
// Destroy(), or nothing gets cleaned up.
- llvm::OwningPtr<CallExpr> TheCall(new (Context) CallExpr(Fn, Args, NumArgs,
+ ExprOwningPtr<CallExpr> TheCall(this, new (Context) CallExpr(Fn, Args,NumArgs,
Context.BoolTy, RParenLoc));
const FunctionType *FuncT;
@@ -4154,7 +4153,7 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
// Offset of an array sub-field. TODO: Should we allow vector elements?
const ArrayType *AT = Context.getAsArrayType(Res->getType());
if (!AT) {
- delete Res;
+ Res->Destroy(Context);
return Diag(OC.LocEnd, diag::err_offsetof_array_type) << Res->getType();
}
@@ -4173,7 +4172,7 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
const RecordType *RC = Res->getType()->getAsRecordType();
if (!RC) {
- delete Res;
+ Res->Destroy(Context);
return Diag(OC.LocEnd, diag::err_offsetof_record_type) << Res->getType();
}
@@ -4336,7 +4335,7 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body,
Scope *CurScope) {
// Ensure that CurBlock is deleted.
llvm::OwningPtr<BlockSemaInfo> BSI(CurBlock);
- llvm::OwningPtr<CompoundStmt> Body(static_cast<CompoundStmt*>(body));
+ ExprOwningPtr<CompoundStmt> Body(this, static_cast<CompoundStmt*>(body));
PopDeclContext();
OpenPOWER on IntegriCloud