]> granicus.if.org Git - clang/commitdiff
Transition the PCH support for ShuffleVectorExpr over to ASTContext allocation
authorNate Begeman <natebegeman@mac.com>
Wed, 12 Aug 2009 02:28:50 +0000 (02:28 +0000)
committerNate Begeman <natebegeman@mac.com>
Wed, 12 Aug 2009 02:28:50 +0000 (02:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78783 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/Frontend/PCHReaderStmt.cpp

index 745ba26f70fee0009c0c1b2f78f6bb39a2caba80..7776e497f6f901efe86d3b8de4a1909683ea844f 100644 (file)
@@ -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<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!");
index ce8bb516c09074130256f7fd9aede267c69b0e8f..cfcbca47301d84e41082b9c9e7ac230cf340698f 100644 (file)
@@ -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) {
index 3040a52260b4835747474f90f342ee830bcae3e1..ccf585ce085097b7663ea885e3b219d06866b79a 100644 (file)
@@ -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;