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 745ba26..7776e49 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -1726,6 +1726,9 @@
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 @@
}
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 @@
assert((Index < NumExprs) && "Arg access out of range!");
return cast<Expr>(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 ce8bb51..cfcbca4 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -1596,13 +1596,20 @@
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 3040a52..ccf585c 100644
--- a/lib/Frontend/PCHReaderStmt.cpp
+++ b/lib/Frontend/PCHReaderStmt.cpp
@@ -666,7 +666,8 @@
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;