From: Ted Kremenek Date: Mon, 9 Feb 2009 17:08:14 +0000 (+0000) Subject: Allocate the subexpression array for OberloadExpr from ASTContext's allocator. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb7413f12636cefa9ebec9abf95804f82c305b11;p=clang Allocate the subexpression array for OberloadExpr from ASTContext's allocator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64145 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 68e486c21b..55b31b4369 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1533,17 +1533,18 @@ class OverloadExpr : public Expr { SourceLocation BuiltinLoc; SourceLocation RParenLoc; public: - OverloadExpr(Expr **args, unsigned nexprs, unsigned idx, QualType t, - SourceLocation bloc, SourceLocation rploc) + OverloadExpr(ASTContext& C, Expr **args, unsigned nexprs, unsigned idx, + QualType t, SourceLocation bloc, SourceLocation rploc) : Expr(OverloadExprClass, t), NumExprs(nexprs), FnIndex(idx), BuiltinLoc(bloc), RParenLoc(rploc) { - SubExprs = new Stmt*[nexprs]; + SubExprs = new (C) Stmt*[nexprs]; for (unsigned i = 0; i != nexprs; ++i) SubExprs[i] = args[i]; } - ~OverloadExpr() { - delete [] SubExprs; - } + + ~OverloadExpr() {} + + void Destroy(ASTContext& C); /// arg_begin - Return a pointer to the list of arguments that will be passed /// to the matching candidate function, skipping over the initial constant diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 904fe5f99c..e541bb8a82 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1410,6 +1410,13 @@ void SizeOfAlignOfExpr::Destroy(ASTContext& C) { Expr::Destroy(C); } +void OverloadExpr::Destroy(ASTContext& C) { + DestroyChildren(C); + C.Deallocate(SubExprs); + this->~OverloadExpr(); + C.Deallocate(this); +} + //===----------------------------------------------------------------------===// // DesignatedInitExpr //===----------------------------------------------------------------------===// diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp index 92713cc633..4d92245f75 100644 --- a/lib/AST/StmtSerialization.cpp +++ b/lib/AST/StmtSerialization.cpp @@ -937,7 +937,7 @@ OverloadExpr* OverloadExpr::CreateImpl(llvm::Deserializer& D, ASTContext& C) { // FIXME: Avoid extra allocation. llvm::SmallVector Exprs(NumExprs); D.BatchReadOwnedPtrs(NumExprs, Exprs.begin(), C); - return new OverloadExpr(Exprs.begin(), NumExprs, FnIndex, T, BL, RP); + return new OverloadExpr(C, Exprs.begin(), NumExprs, FnIndex, T, BL, RP); } void VAArgExpr::EmitImpl(llvm::Serializer& S) const { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c12440322d..f881e81bf4 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4369,7 +4369,7 @@ Sema::ExprResult Sema::ActOnOverloadExpr(ExprTy **args, unsigned NumArgs, << OE->getFn()->getSourceRange(); // Remember our match, and continue processing the remaining arguments // to catch any errors. - OE = new (Context) OverloadExpr(Args, NumArgs, i, + OE = new (Context) OverloadExpr(Context, Args, NumArgs, i, FnType->getResultType().getNonReferenceType(), BuiltinLoc, RParenLoc); }