[cfe-commits] r78783 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Frontend/PCHReaderStmt.cpp

Nate Begeman natebegeman at mac.com
Tue Aug 11 19:28:50 PDT 2009


Author: sampo
Date: Tue Aug 11 21:28:50 2009
New Revision: 78783

URL: http://llvm.org/viewvc/llvm-project?rev=78783&view=rev
Log:
Transition the PCH support for ShuffleVectorExpr over to ASTContext allocation

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Frontend/PCHReaderStmt.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=78783&r1=78782&r2=78783&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Aug 11 21:28:50 2009
@@ -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!");

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=78783&r1=78782&r2=78783&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Aug 11 21:28:50 2009
@@ -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) {

Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=78783&r1=78782&r2=78783&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Tue Aug 11 21:28:50 2009
@@ -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;





More information about the cfe-commits mailing list