From: Nate Begeman Date: Wed, 12 Aug 2009 02:28:50 +0000 (+0000) Subject: Transition the PCH support for ShuffleVectorExpr over to ASTContext allocation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=888376a2bbcfc2f047902249f8455918e2489ae1;p=clang Transition the PCH support for ShuffleVectorExpr over to ASTContext allocation git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78783 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 745ba26f70..7776e497f6 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1726,6 +1726,9 @@ class ShuffleVectorExpr : public Expr { Stmt **SubExprs; unsigned NumExprs; +protected: + virtual void DoDestroy(ASTContext &C); + public: ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, QualType Type, SourceLocation BLoc, @@ -1756,9 +1759,7 @@ public: } static bool classof(const ShuffleVectorExpr *) { return true; } - ~ShuffleVectorExpr() { - delete [] SubExprs; - } + ~ShuffleVectorExpr() {} /// getNumSubExprs - Return the size of the SubExprs array. This includes the /// constant expression, the actual arguments passed in, and the function @@ -1774,8 +1775,8 @@ public: assert((Index < NumExprs) && "Arg access out of range!"); return cast(SubExprs[Index]); } - - void setExprs(Expr ** Exprs, unsigned NumExprs); + + void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { assert((N < NumExprs - 2) && "Shuffle idx out of range!"); diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index ce8bb516c0..cfcbca4730 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1596,13 +1596,20 @@ bool ChooseExpr::isConditionTrue(ASTContext &C) const { return getCond()->EvaluateAsInt(C) != 0; } -void ShuffleVectorExpr::setExprs(Expr ** Exprs, unsigned NumExprs) { - if (NumExprs) - delete [] SubExprs; - - SubExprs = new Stmt* [NumExprs]; +void ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, + unsigned NumExprs) { + if (SubExprs) C.Deallocate(SubExprs); + + SubExprs = new (C) Stmt* [NumExprs]; this->NumExprs = NumExprs; memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); +} + +void ShuffleVectorExpr::DoDestroy(ASTContext& C) { + DestroyChildren(C); + if (SubExprs) C.Deallocate(SubExprs); + this->~ShuffleVectorExpr(); + C.Deallocate(this); } void SizeOfAlignOfExpr::DoDestroy(ASTContext& C) { diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index 3040a52260..ccf585ce08 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -666,7 +666,8 @@ unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) { unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { VisitExpr(E); unsigned NumExprs = Record[Idx++]; - E->setExprs((Expr **)&StmtStack[StmtStack.size() - NumExprs], NumExprs); + E->setExprs(*Reader.getContext(), + (Expr **)&StmtStack[StmtStack.size() - NumExprs], NumExprs); E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); return NumExprs;