aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaOverload.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
commit8189cde56b4f6f938cd65f53c932fe1860d0204c (patch)
tree071221f15cf949ffcf6023f72528dd8c4ea487cb /lib/Sema/SemaOverload.cpp
parentcad2996edf303978932c621ab02729dc11debb81 (diff)
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
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r--lib/Sema/SemaOverload.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index cb659002b3..69bbf0e05a 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -3600,9 +3600,9 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
// Extract the object argument.
Expr *ObjectArg = MemExpr->getBase();
if (MemExpr->isArrow())
- ObjectArg = new UnaryOperator(ObjectArg, UnaryOperator::Deref,
- ObjectArg->getType()->getAsPointerType()->getPointeeType(),
- SourceLocation());
+ ObjectArg = new (Context) UnaryOperator(ObjectArg, UnaryOperator::Deref,
+ ObjectArg->getType()->getAsPointerType()->getPointeeType(),
+ SourceLocation());
CXXMethodDecl *Method = 0;
if (OverloadedFunctionDecl *Ovl
= dyn_cast<OverloadedFunctionDecl>(MemExpr->getMemberDecl())) {
@@ -3647,8 +3647,8 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
}
assert(Method && "Member call to something that isn't a method?");
- llvm::OwningPtr<CXXMemberCallExpr>
- TheCall(new CXXMemberCallExpr(MemExpr, Args, NumArgs,
+ ExprOwningPtr<CXXMemberCallExpr>
+ TheCall(this, new (Context) CXXMemberCallExpr(MemExpr, Args, NumArgs,
Method->getResultType().getNonReferenceType(),
RParenLoc));
@@ -3759,9 +3759,9 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
if (Best == CandidateSet.end()) {
// We had an error; delete all of the subexpressions and return
// the error.
- delete Object;
+ Object->Destroy(Context);
for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx)
- delete Args[ArgIdx];
+ Args[ArgIdx]->Destroy(Context);
return true;
}
@@ -3807,22 +3807,23 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx)
MethodArgs[ArgIdx + 1] = Args[ArgIdx];
- Expr *NewFn = new DeclRefExpr(Method, Method->getType(),
- SourceLocation());
+ Expr *NewFn = new (Context) DeclRefExpr(Method, Method->getType(),
+ SourceLocation());
UsualUnaryConversions(NewFn);
// Once we've built TheCall, all of the expressions are properly
// owned.
QualType ResultTy = Method->getResultType().getNonReferenceType();
- llvm::OwningPtr<CXXOperatorCallExpr>
- TheCall(new CXXOperatorCallExpr(NewFn, MethodArgs, NumArgs + 1,
- ResultTy, RParenLoc));
+ ExprOwningPtr<CXXOperatorCallExpr>
+ TheCall(this, new (Context) CXXOperatorCallExpr(NewFn, MethodArgs,
+ NumArgs + 1,
+ ResultTy, RParenLoc));
delete [] MethodArgs;
// We may have default arguments. If so, we need to allocate more
// slots in the call for them.
if (NumArgs < NumArgsInProto)
- TheCall->setNumArgs(NumArgsInProto + 1);
+ TheCall->setNumArgs(Context, NumArgsInProto + 1);
else if (NumArgs > NumArgsInProto)
NumArgsToCheck = NumArgsInProto;
@@ -3842,7 +3843,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
return true;
} else {
- Arg = new CXXDefaultArgExpr(Method->getParamDecl(i));
+ Arg = new (Context) CXXDefaultArgExpr(Method->getParamDecl(i));
}
TheCall->setArg(i + 1, Arg);
@@ -3888,7 +3889,7 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Base, 0, 0, CandidateSet,
/*SuppressUserConversions=*/false);
- llvm::OwningPtr<Expr> BasePtr(Base);
+ ExprOwningPtr<Expr> BasePtr(this, Base);
// Perform overload resolution.
OverloadCandidateSet::iterator Best;
@@ -3924,9 +3925,10 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
BasePtr.take();
// Build the operator call.
- Expr *FnExpr = new DeclRefExpr(Method, Method->getType(), SourceLocation());
+ Expr *FnExpr = new (Context) DeclRefExpr(Method, Method->getType(),
+ SourceLocation());
UsualUnaryConversions(FnExpr);
- Base = new CXXOperatorCallExpr(FnExpr, &Base, 1,
+ Base = new (Context) CXXOperatorCallExpr(FnExpr, &Base, 1,
Method->getResultType().getNonReferenceType(),
OpLoc);
return ActOnMemberReferenceExpr(S, ExprArg(*this, Base), OpLoc, tok::arrow,