[cfe-commits] r63997 - in /cfe/trunk: Driver/RewriteObjC.cpp include/clang/AST/Expr.h include/clang/AST/Stmt.h lib/AST/Expr.cpp lib/AST/ExprCXX.cpp lib/AST/Stmt.cpp lib/AST/StmtSerialization.cpp lib/Sema/Sema.cpp lib/Sema/Sema.h lib/Sema/SemaChecking.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaExprObjC.cpp lib/Sema/SemaNamedCast.cpp lib/Sema/SemaOverload.cpp lib/Sema/SemaStmt.cpp lib/Sema/SemaType.cpp

Ted Kremenek kremenek at apple.com
Fri Feb 6 17:47:30 PST 2009


Author: kremenek
Date: Fri Feb  6 19:47:29 2009
New Revision: 63997

URL: http://llvm.org/viewvc/llvm-project?rev=63997&view=rev
Log:
Overhaul of Stmt allocation:
- Made allocation of Stmt objects using vanilla new/delete a *compiler
  error* by making this new/delete "protected" within class Stmt.
- Now the only way to allocate Stmt objects is by using the new
  operator that takes ASTContext& as an argument.  This ensures that
  all Stmt nodes are allocated from the same (pool) allocator.
- Naturally, these two changes required that *all* creation sites for
  AST nodes use new (ASTContext&).  This is a large patch, but the
  majority of the changes are just this mechanical adjustment.
- The above changes also mean that AST nodes can no longer be
  deallocated using 'delete'.  Instead, one most do
  StmtObject->Destroy(ASTContext&) or do
  ASTContextObject.Deallocate(StmtObject) (the latter not running the
  'Destroy' method).

Along the way I also...
- Made CompoundStmt allocate its array of Stmt* using the allocator in
  ASTContext (previously it used std::vector).  There are a whole
  bunch of other Stmt classes that need to be similarly changed to
  ensure that all memory allocated for ASTs comes from the allocator
  in ASTContext.
- Added a new smart pointer ExprOwningPtr to Sema.h.  This replaces
  the uses of llvm::OwningPtr within Sema, as llvm::OwningPtr used
  'delete' to free memory instead of a Stmt's 'Destroy' method.

Big thanks to Doug Gregor for helping with the acrobatics of making
'new/delete' private and the new smart pointer ExprOwningPtr!

Modified:
    cfe/trunk/Driver/RewriteObjC.cpp
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/AST/ExprCXX.cpp
    cfe/trunk/lib/AST/Stmt.cpp
    cfe/trunk/lib/AST/StmtSerialization.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/lib/Sema/SemaNamedCast.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Fri Feb  6 19:47:29 2009
@@ -339,7 +339,9 @@
     
     // We avoid calling Type::isBlockPointerType(), since it operates on the
     // canonical type. We only care if the top-level type is a closure pointer.
-    bool isTopLevelBlockPointerType(QualType T) { return isa<BlockPointerType>(T); }
+    bool isTopLevelBlockPointerType(QualType T) {
+      return isa<BlockPointerType>(T);
+    }
     
     // FIXME: This predicate seems like it would be useful to add to ASTContext.
     bool isObjCType(QualType T) {
@@ -360,7 +362,8 @@
       return false;
     }
     bool PointerTypeTakesAnyBlockArguments(QualType QT);
-    void GetExtentOfArgList(const char *Name, const char *&LParen, const char *&RParen);
+    void GetExtentOfArgList(const char *Name, const char *&LParen,
+                            const char *&RParen);
     void RewriteCastExpr(CStyleCastExpr *CE);
     
     FunctionDecl *SynthBlockInitFunctionDecl(const char *name);
@@ -410,7 +413,8 @@
   RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning, 
                "rewriting sub-expression within a macro (may not be correct)");
   TryFinallyContainsReturnDiag = Diags.getCustomDiagID(Diagnostic::Warning, 
-               "rewriter doesn't support user-specified control flow semantics for @try/@finally (code may not execute properly)");
+               "rewriter doesn't support user-specified control flow semantics "
+               "for @try/@finally (code may not execute properly)");
 }
 
 ASTConsumer *clang::CreateCodeRewriterTest(const std::string& InFile,
@@ -465,7 +469,8 @@
   Preamble += "struct objc_object *superClass; ";
   if (LangOpts.Microsoft) {
     // Add a constructor for creating temporary objects.
-    Preamble += "__rw_objc_super(struct objc_object *o, struct objc_object *s) : ";
+    Preamble += "__rw_objc_super(struct objc_object *o, struct objc_object *s) "
+                ": ";
     Preamble += "object(o), superClass(s) {} ";
   }
   Preamble += "};\n";
@@ -672,7 +677,8 @@
   assert((*startBuf == '@') && "bogus @synthesize location");
   const char *semiBuf = strchr(startBuf, ';');
   assert((*semiBuf == ';') && "@synthesize: can't find ';'");
-  SourceLocation onePastSemiLoc = startLoc.getFileLocWithOffset(semiBuf-startBuf+1);
+  SourceLocation onePastSemiLoc =
+    startLoc.getFileLocWithOffset(semiBuf-startBuf+1);
 
   if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
     return; // FIXME: is this correct?
@@ -1066,7 +1072,7 @@
     // This allows us to handle chain/nested property getters.
     Receiver = PropGetters[PRE];
   }
-  MsgExpr = new ObjCMessageExpr(dyn_cast<Expr>(Receiver), 
+  MsgExpr = new (Context) ObjCMessageExpr(dyn_cast<Expr>(Receiver), 
                                 PDecl->getSetterName(), PDecl->getType(), 
                                 PDecl->getSetterMethodDecl(), 
                                 SourceLocation(), SourceLocation(), 
@@ -1076,7 +1082,9 @@
   // Now do the actual rewrite.
   ReplaceStmtWithRange(BinOp, ReplacingStmt, SrcRange);
   //delete BinOp;
-  delete MsgExpr;
+  // NOTE: We don't want to call MsgExpr->Destroy(), as it holds references
+  // to things that stay around.
+  Context->Deallocate(MsgExpr);
   return ReplacingStmt;
 }
 
@@ -1093,7 +1101,7 @@
     // This allows us to handle chain/nested property getters.
     Receiver = PropGetters[PRE];
   }
-  MsgExpr = new ObjCMessageExpr(dyn_cast<Expr>(Receiver), 
+  MsgExpr = new (Context) ObjCMessageExpr(dyn_cast<Expr>(Receiver), 
                                 PDecl->getGetterName(), PDecl->getType(), 
                                 PDecl->getGetterMethodDecl(), 
                                 SourceLocation(), SourceLocation(), 
@@ -1109,12 +1117,16 @@
     // We stash away the ReplacingStmt since actually doing the
     // replacement/rewrite won't work for nested getters (e.g. obj.p.i)
     PropGetters[PropRefExpr] = ReplacingStmt;
-    delete MsgExpr;
+    // NOTE: We don't want to call MsgExpr->Destroy(), as it holds references
+    // to things that stay around.
+    Context->Deallocate(MsgExpr);
     return PropRefExpr; // return the original...
   } else {
     ReplaceStmt(PropRefExpr, ReplacingStmt);
-    // delete PropRefExpr; elsewhere...
-    delete MsgExpr;
+    // delete PropRefExpr; elsewhere...    
+    // NOTE: We don't want to call MsgExpr->Destroy(), as it holds references
+    // to things that stay around.
+    Context->Deallocate(MsgExpr);
     return ReplacingStmt;
   }
 }
@@ -1124,7 +1136,8 @@
   ObjCIvarDecl *D = IV->getDecl();
   if (CurMethodDef) {
     if (const PointerType *pType = IV->getBase()->getType()->getAsPointerType()) {
-      ObjCInterfaceType *iFaceDecl = dyn_cast<ObjCInterfaceType>(pType->getPointeeType());
+      ObjCInterfaceType *iFaceDecl =
+        dyn_cast<ObjCInterfaceType>(pType->getPointeeType());
       // lookup which class implements the instance variable.
       ObjCInterfaceDecl *clsDeclared = 0;
       iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), clsDeclared);
@@ -1138,16 +1151,18 @@
                                           SourceLocation(), II);
       assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
       QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
-      CastExpr *castExpr = new CStyleCastExpr(castT, IV->getBase(), castT,
-                                                 SourceLocation(), SourceLocation());
+      CastExpr *castExpr = new (Context) CStyleCastExpr(castT, IV->getBase(),
+                                                         castT,SourceLocation(),
+                                                         SourceLocation());
       // Don't forget the parens to enforce the proper binding.
-      ParenExpr *PE = new ParenExpr(IV->getBase()->getLocStart(),
-                                    IV->getBase()->getLocEnd(),
-                                    castExpr);
+      ParenExpr *PE = new (Context) ParenExpr(IV->getBase()->getLocStart(),
+                                               IV->getBase()->getLocEnd(),
+                                               castExpr);
       if (IV->isFreeIvar() && 
           CurMethodDef->getClassInterface() == iFaceDecl->getDecl()) {
-        MemberExpr *ME = new MemberExpr(PE, true, D, IV->getLocation(),
-                                        D->getType());
+        MemberExpr *ME = new (Context) MemberExpr(PE, true, D,
+                                                   IV->getLocation(),
+                                                   D->getType());
         ReplaceStmt(IV, ME);
         // delete IV; leak for now, see RewritePropertySetter() usage for more info.
         return ME;
@@ -1180,10 +1195,11 @@
                                           SourceLocation(), II);
       assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
       QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
-      CastExpr *castExpr = new CStyleCastExpr(castT, IV->getBase(), castT,
-                                                 SourceLocation(), SourceLocation());
+      CastExpr *castExpr = new (Context) CStyleCastExpr(castT, IV->getBase(),
+                                                        castT, SourceLocation(),
+                                                        SourceLocation());
       // Don't forget the parens to enforce the proper binding.
-      ParenExpr *PE = new ParenExpr(IV->getBase()->getLocStart(),
+      ParenExpr *PE = new (Context) ParenExpr(IV->getBase()->getLocStart(),
                                     IV->getBase()->getLocEnd(), castExpr);
       ReplaceStmt(IV->getBase(), PE);
       // Cannot delete IV->getBase(), since PE points to it.
@@ -1475,10 +1491,11 @@
   buf += "  _rethrow = objc_exception_extract(&_stack);\n";
   buf += "  if (!_rethrow) objc_exception_try_exit(&_stack);\n";
   buf += "  objc_sync_exit(";
-  Expr *syncExpr = new CStyleCastExpr(Context->getObjCIdType(), 
-                                         S->getSynchExpr(), 
-                                         Context->getObjCIdType(),
-                                         SourceLocation(), SourceLocation());
+  Expr *syncExpr = new (Context) CStyleCastExpr(Context->getObjCIdType(), 
+                                                S->getSynchExpr(), 
+                                                Context->getObjCIdType(),
+                                                SourceLocation(),
+                                                SourceLocation());
   std::string syncExprBufS;
   llvm::raw_string_ostream syncExprBuf(syncExprBufS);
   syncExpr->printPretty(syncExprBuf);
@@ -1717,7 +1734,7 @@
   QualType StrType = Context->getPointerType(Context->CharTy);
   std::string StrEncoding;
   Context->getObjCEncodingForType(Exp->getEncodedType(), StrEncoding);
-  Expr *Replacement = new (*Context) StringLiteral(*Context,StrEncoding.c_str(),
+  Expr *Replacement = new (Context) StringLiteral(*Context,StrEncoding.c_str(),
                                         StrEncoding.length(), false, StrType, 
                                         SourceLocation(), SourceLocation());
   ReplaceStmt(Exp, Replacement);
@@ -1734,7 +1751,7 @@
   // Create a call to sel_registerName("selName").
   llvm::SmallVector<Expr*, 8> SelExprs;
   QualType argType = Context->getPointerType(Context->CharTy);
-  SelExprs.push_back(new (*Context) StringLiteral((*Context), 
+  SelExprs.push_back(new (Context) StringLiteral((*Context), 
                                        Exp->getSelector().getAsString().c_str(),
                                        Exp->getSelector().getAsString().size(),
                                        false, argType, SourceLocation(),
@@ -1752,16 +1769,16 @@
   QualType msgSendType = FD->getType();
   
   // Create a reference to the objc_msgSend() declaration.
-  DeclRefExpr *DRE = new DeclRefExpr(FD, msgSendType, SourceLocation());
+  DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, msgSendType, SourceLocation());
                                      
   // Now, we cast the reference to a pointer to the objc_msgSend type.
   QualType pToFunc = Context->getPointerType(msgSendType);
-  ImplicitCastExpr *ICE = new ImplicitCastExpr(pToFunc, DRE, 
+  ImplicitCastExpr *ICE = new (Context) ImplicitCastExpr(pToFunc, DRE, 
                                                /*isLvalue=*/false);
   
   const FunctionType *FT = msgSendType->getAsFunctionType();
   
-  return new CallExpr(ICE, args, nargs, FT->getResultType(), SourceLocation());
+  return new (Context) CallExpr(ICE, args, nargs, FT->getResultType(), SourceLocation());
 }
 
 static bool scanForProtocolRefs(const char *startBuf, const char *endBuf,
@@ -2134,12 +2151,12 @@
   VarDecl *NewVD = VarDecl::Create(*Context, TUDecl, SourceLocation(), 
                                     &Context->Idents.get(S.c_str()), strType, 
                                     VarDecl::Static);
-  DeclRefExpr *DRE = new DeclRefExpr(NewVD, strType, SourceLocation());
-  Expr *Unop = new UnaryOperator(DRE, UnaryOperator::AddrOf,
+  DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, strType, SourceLocation());
+  Expr *Unop = new (Context) UnaryOperator(DRE, UnaryOperator::AddrOf,
                                  Context->getPointerType(DRE->getType()), 
                                  SourceLocation());
   // cast to NSConstantString *
-  CastExpr *cast = new CStyleCastExpr(Exp->getType(), Unop, 
+  CastExpr *cast = new (Context) CStyleCastExpr(Exp->getType(), Unop, 
                                          Exp->getType(), SourceLocation(), SourceLocation());
   ReplaceStmt(Exp, cast);
   // delete Exp; leak for now, see RewritePropertySetter() usage for more info.
@@ -2266,13 +2283,13 @@
       llvm::SmallVector<Expr*, 4> InitExprs;
       
       // set the receiver to self, the first argument to all methods.
-      InitExprs.push_back(new DeclRefExpr(
+      InitExprs.push_back(new (Context) DeclRefExpr(
             CurMethodDef->getSelfDecl(), 
             Context->getObjCIdType(),
             SourceLocation())); 
       llvm::SmallVector<Expr*, 8> ClsExprs;
       QualType argType = Context->getPointerType(Context->CharTy);
-      ClsExprs.push_back(new (*Context) StringLiteral(*Context,
+      ClsExprs.push_back(new (Context) StringLiteral(*Context,
                                         SuperDecl->getIdentifier()->getName(), 
                                         SuperDecl->getIdentifier()->getLength(),
                                         false, argType, SourceLocation(),
@@ -2282,7 +2299,7 @@
                                                    ClsExprs.size());
       // To turn off a warning, type-cast to 'id'
       InitExprs.push_back( // set 'super class', using objc_getClass().
-        new CStyleCastExpr(Context->getObjCIdType(), 
+        new (Context) CStyleCastExpr(Context->getObjCIdType(), 
                               Cls, Context->getObjCIdType(),
                               SourceLocation(), SourceLocation())); 
       // struct objc_super
@@ -2292,9 +2309,9 @@
       if (LangOpts.Microsoft) {
         SynthSuperContructorFunctionDecl();
         // Simulate a contructor call...
-        DeclRefExpr *DRE = new DeclRefExpr(SuperContructorFunctionDecl, 
+        DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, 
                                            superType, SourceLocation());
-        SuperRep = new CallExpr(DRE, &InitExprs[0], InitExprs.size(), 
+        SuperRep = new (Context) CallExpr(DRE, &InitExprs[0], InitExprs.size(), 
                                 superType, SourceLocation());
         // The code for super is a little tricky to prevent collision with
         // the structure definition in the header. The rewriter has it's own
@@ -2302,21 +2319,21 @@
         // we need the cast below. For example:
         // (struct objc_super *)&__rw_objc_super((id)self, (id)objc_getClass("SUPER"))
         //
-        SuperRep = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
+        SuperRep = new (Context) UnaryOperator(SuperRep, UnaryOperator::AddrOf,
                                  Context->getPointerType(SuperRep->getType()), 
                                  SourceLocation());
-        SuperRep = new CStyleCastExpr(Context->getPointerType(superType), 
+        SuperRep = new (Context) CStyleCastExpr(Context->getPointerType(superType), 
                                  SuperRep, Context->getPointerType(superType),
                                  SourceLocation(), SourceLocation()); 
       } else {      
         // (struct objc_super) { <exprs from above> }
-        InitListExpr *ILE = new InitListExpr(SourceLocation(), 
+        InitListExpr *ILE = new (Context) InitListExpr(SourceLocation(), 
                                              &InitExprs[0], InitExprs.size(), 
                                              SourceLocation());
-        SuperRep = new CompoundLiteralExpr(SourceLocation(), superType, ILE,
+        SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), superType, ILE,
                                            false);
         // struct objc_super *
-        SuperRep = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
+        SuperRep = new (Context) UnaryOperator(SuperRep, UnaryOperator::AddrOf,
                                  Context->getPointerType(SuperRep->getType()), 
                                  SourceLocation());
       }
@@ -2324,7 +2341,7 @@
     } else {
       llvm::SmallVector<Expr*, 8> ClsExprs;
       QualType argType = Context->getPointerType(Context->CharTy);
-      ClsExprs.push_back(new (*Context) StringLiteral(*Context,
+      ClsExprs.push_back(new (Context) StringLiteral(*Context,
                                            clsName->getName(), 
                                            clsName->getLength(),
                                            false, argType, SourceLocation(),
@@ -2346,8 +2363,8 @@
       llvm::SmallVector<Expr*, 4> InitExprs;
       
       InitExprs.push_back(
-        new CStyleCastExpr(Context->getObjCIdType(), 
-                     new DeclRefExpr(CurMethodDef->getSelfDecl(), 
+        new (Context) CStyleCastExpr(Context->getObjCIdType(), 
+                     new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), 
                                      Context->getObjCIdType(),
                                      SourceLocation()),
                      Context->getObjCIdType(),
@@ -2355,7 +2372,7 @@
       
       llvm::SmallVector<Expr*, 8> ClsExprs;
       QualType argType = Context->getPointerType(Context->CharTy);
-      ClsExprs.push_back(new (*Context) StringLiteral(*Context, 
+      ClsExprs.push_back(new (Context) StringLiteral(*Context, 
                                         SuperDecl->getIdentifier()->getName(), 
                                         SuperDecl->getIdentifier()->getLength(),
                                         false, argType, SourceLocation(),
@@ -2366,7 +2383,7 @@
       // To turn off a warning, type-cast to 'id'
       InitExprs.push_back(
         // set 'super class', using objc_getClass().
-        new CStyleCastExpr(Context->getObjCIdType(), 
+        new (Context) CStyleCastExpr(Context->getObjCIdType(), 
         Cls, Context->getObjCIdType(), SourceLocation(), SourceLocation())); 
       // struct objc_super
       QualType superType = getSuperStructType();
@@ -2375,9 +2392,9 @@
       if (LangOpts.Microsoft) {
         SynthSuperContructorFunctionDecl();
         // Simulate a contructor call...
-        DeclRefExpr *DRE = new DeclRefExpr(SuperContructorFunctionDecl, 
+        DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, 
                                            superType, SourceLocation());
-        SuperRep = new CallExpr(DRE, &InitExprs[0], InitExprs.size(), 
+        SuperRep = new (Context) CallExpr(DRE, &InitExprs[0], InitExprs.size(), 
                                 superType, SourceLocation());
         // The code for super is a little tricky to prevent collision with
         // the structure definition in the header. The rewriter has it's own
@@ -2385,18 +2402,18 @@
         // we need the cast below. For example:
         // (struct objc_super *)&__rw_objc_super((id)self, (id)objc_getClass("SUPER"))
         //
-        SuperRep = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
+        SuperRep = new (Context) UnaryOperator(SuperRep, UnaryOperator::AddrOf,
                                  Context->getPointerType(SuperRep->getType()), 
                                  SourceLocation());
-        SuperRep = new CStyleCastExpr(Context->getPointerType(superType), 
+        SuperRep = new (Context) CStyleCastExpr(Context->getPointerType(superType), 
                                  SuperRep, Context->getPointerType(superType),
                                  SourceLocation(), SourceLocation()); 
       } else {
         // (struct objc_super) { <exprs from above> }
-        InitListExpr *ILE = new InitListExpr(SourceLocation(), 
+        InitListExpr *ILE = new (Context) InitListExpr(SourceLocation(), 
                                              &InitExprs[0], InitExprs.size(), 
                                              SourceLocation());
-        SuperRep = new CompoundLiteralExpr(SourceLocation(), superType, ILE, false);
+        SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), superType, ILE, false);
       }
       MsgExprs.push_back(SuperRep);
     } else {
@@ -2404,7 +2421,7 @@
       // Foo<Proto> *.
       while (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(recExpr))
         recExpr = CE->getSubExpr();
-      recExpr = new CStyleCastExpr(Context->getObjCIdType(), recExpr,
+      recExpr = new (Context) CStyleCastExpr(Context->getObjCIdType(), recExpr,
                                       Context->getObjCIdType(), 
                                       SourceLocation(), SourceLocation());
       MsgExprs.push_back(recExpr);
@@ -2413,7 +2430,7 @@
   // Create a call to sel_registerName("selName"), it will be the 2nd argument.
   llvm::SmallVector<Expr*, 8> SelExprs;
   QualType argType = Context->getPointerType(Context->CharTy);
-  SelExprs.push_back(new (*Context) StringLiteral(*Context, 
+  SelExprs.push_back(new (Context) StringLiteral(*Context, 
                                        Exp->getSelector().getAsString().c_str(),
                                        Exp->getSelector().getAsString().size(),
                                        false, argType, SourceLocation(),
@@ -2431,14 +2448,14 @@
       QualType type = ICE->getType()->isObjCQualifiedIdType()
                                 ? Context->getObjCIdType()
                                 : ICE->getType();
-      userExpr = new CStyleCastExpr(type, userExpr, type, SourceLocation(), SourceLocation());
+      userExpr = new (Context) CStyleCastExpr(type, userExpr, type, SourceLocation(), SourceLocation());
     }
     // Make id<P...> cast into an 'id' cast.
     else if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(userExpr)) {
       if (CE->getType()->isObjCQualifiedIdType()) {
         while ((CE = dyn_cast<CStyleCastExpr>(userExpr)))
           userExpr = CE->getSubExpr();
-        userExpr = new CStyleCastExpr(Context->getObjCIdType(), 
+        userExpr = new (Context) CStyleCastExpr(Context->getObjCIdType(), 
                                 userExpr, Context->getObjCIdType(), 
                                 SourceLocation(), SourceLocation());
       }
@@ -2481,14 +2498,14 @@
   QualType msgSendType = MsgSendFlavor->getType();
   
   // Create a reference to the objc_msgSend() declaration.
-  DeclRefExpr *DRE = new DeclRefExpr(MsgSendFlavor, msgSendType, 
+  DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, msgSendType, 
                                      SourceLocation());
 
   // Need to cast objc_msgSend to "void *" (to workaround a GCC bandaid). 
   // If we don't do this cast, we get the following bizarre warning/note:
   // xx.m:13: warning: function called through a non-compatible type
   // xx.m:13: note: if this code is reached, the program will abort
-  cast = new CStyleCastExpr(Context->getPointerType(Context->VoidTy), DRE, 
+  cast = new (Context) CStyleCastExpr(Context->getPointerType(Context->VoidTy), DRE, 
                                Context->getPointerType(Context->VoidTy),
                                SourceLocation(), SourceLocation());
     
@@ -2498,13 +2515,13 @@
     // If we don't have a method decl, force a variadic cast.
     Exp->getMethodDecl() ? Exp->getMethodDecl()->isVariadic() : true, 0);
   castType = Context->getPointerType(castType);
-  cast = new CStyleCastExpr(castType, cast, castType, SourceLocation(), SourceLocation());
+  cast = new (Context) CStyleCastExpr(castType, cast, castType, SourceLocation(), SourceLocation());
 
   // Don't forget the parens to enforce the proper binding.
-  ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), cast);
+  ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), cast);
   
   const FunctionType *FT = msgSendType->getAsFunctionType();
-  CallExpr *CE = new CallExpr(PE, &MsgExprs[0], MsgExprs.size(), 
+  CallExpr *CE = new (Context) CallExpr(PE, &MsgExprs[0], MsgExprs.size(), 
                               FT->getResultType(), SourceLocation());
   Stmt *ReplacingStmt = CE;
   if (MsgSendStretFlavor) {
@@ -2514,10 +2531,10 @@
     // method's return type.
     
     // Create a reference to the objc_msgSend_stret() declaration.
-    DeclRefExpr *STDRE = new DeclRefExpr(MsgSendStretFlavor, msgSendType, 
+    DeclRefExpr *STDRE = new (Context) DeclRefExpr(MsgSendStretFlavor, msgSendType, 
                                          SourceLocation());
     // Need to cast objc_msgSend_stret to "void *" (see above comment).
-    cast = new CStyleCastExpr(Context->getPointerType(Context->VoidTy), STDRE, 
+    cast = new (Context) CStyleCastExpr(Context->getPointerType(Context->VoidTy), STDRE, 
                                  Context->getPointerType(Context->VoidTy),
                                  SourceLocation(), SourceLocation());
     // Now do the "normal" pointer to function cast.
@@ -2525,17 +2542,17 @@
       &ArgTypes[0], ArgTypes.size(),
       Exp->getMethodDecl() ? Exp->getMethodDecl()->isVariadic() : false, 0);
     castType = Context->getPointerType(castType);
-    cast = new CStyleCastExpr(castType, cast, castType, SourceLocation(), SourceLocation());
+    cast = new (Context) CStyleCastExpr(castType, cast, castType, SourceLocation(), SourceLocation());
     
     // Don't forget the parens to enforce the proper binding.
-    PE = new ParenExpr(SourceLocation(), SourceLocation(), cast);
+    PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), cast);
     
     FT = msgSendType->getAsFunctionType();
-    CallExpr *STCE = new CallExpr(PE, &MsgExprs[0], MsgExprs.size(), 
+    CallExpr *STCE = new (Context) CallExpr(PE, &MsgExprs[0], MsgExprs.size(), 
                                   FT->getResultType(), SourceLocation());
     
     // Build sizeof(returnType)
-    SizeOfAlignOfExpr *sizeofExpr = new SizeOfAlignOfExpr(true, true,
+    SizeOfAlignOfExpr *sizeofExpr = new (Context) SizeOfAlignOfExpr(true, true,
                                       returnType.getAsOpaquePtr(),
                                       Context->getSizeType(),
                                       SourceLocation(), SourceLocation());
@@ -2545,17 +2562,17 @@
     // is needed to decide what to do.
     unsigned IntSize = 
       static_cast<unsigned>(Context->getTypeSize(Context->IntTy));
-    IntegerLiteral *limit = new IntegerLiteral(llvm::APInt(IntSize, 8), 
+    IntegerLiteral *limit = new (Context) IntegerLiteral(llvm::APInt(IntSize, 8), 
                                                Context->IntTy,
                                                SourceLocation());
-    BinaryOperator *lessThanExpr = new BinaryOperator(sizeofExpr, limit, 
+    BinaryOperator *lessThanExpr = new (Context) BinaryOperator(sizeofExpr, limit, 
                                                       BinaryOperator::LE, 
                                                       Context->IntTy, 
                                                       SourceLocation());
     // (sizeof(returnType) <= 8 ? objc_msgSend(...) : objc_msgSend_stret(...))
     ConditionalOperator *CondExpr = 
-      new ConditionalOperator(lessThanExpr, CE, STCE, returnType);
-    ReplacingStmt = new ParenExpr(SourceLocation(), SourceLocation(), CondExpr);
+      new (Context) ConditionalOperator(lessThanExpr, CE, STCE, returnType);
+    ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(), CondExpr);
   }
   return ReplacingStmt;
 }
@@ -2579,7 +2596,7 @@
   // Create a call to objc_getProtocol("ProtocolName").
   llvm::SmallVector<Expr*, 8> ProtoExprs;
   QualType argType = Context->getPointerType(Context->CharTy);
-  ProtoExprs.push_back(new (*Context) 
+  ProtoExprs.push_back(new (Context) 
                        StringLiteral(*Context,
                                 Exp->getProtocol()->getNameAsCString(),
                                 strlen(Exp->getProtocol()->getNameAsCString()),
@@ -3819,18 +3836,25 @@
     
   PtrToFuncCastType = Context->getPointerType(PtrToFuncCastType);
   
-  CastExpr *BlkCast = new CStyleCastExpr(PtrBlock, Exp->getCallee(), PtrBlock, SourceLocation(), SourceLocation());
+  CastExpr *BlkCast = new (Context) CStyleCastExpr(PtrBlock, Exp->getCallee(),
+                                                   PtrBlock, SourceLocation(),
+                                                   SourceLocation());
   // Don't forget the parens to enforce the proper binding.
-  ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), BlkCast);
+  ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(),
+                                          BlkCast);
   //PE->dump();
   
   FieldDecl *FD = FieldDecl::Create(*Context, 0, SourceLocation(),
                      &Context->Idents.get("FuncPtr"), Context->VoidPtrTy, 
                                     /*BitWidth=*/0, /*Mutable=*/true);
-  MemberExpr *ME = new MemberExpr(PE, true, FD, SourceLocation(), FD->getType());
+  MemberExpr *ME = new (Context) MemberExpr(PE, true, FD, SourceLocation(),
+                                            FD->getType());
   
-  CastExpr *FunkCast = new CStyleCastExpr(PtrToFuncCastType, ME, PtrToFuncCastType, SourceLocation(), SourceLocation());
-  PE = new ParenExpr(SourceLocation(), SourceLocation(), FunkCast);
+  CastExpr *FunkCast = new (Context) CStyleCastExpr(PtrToFuncCastType, ME,
+                                                    PtrToFuncCastType,
+                                                    SourceLocation(),
+                                                    SourceLocation());
+  PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), FunkCast);
   
   llvm::SmallVector<Expr*, 8> BlkExprs;
   // Add the implicit argument.
@@ -3840,7 +3864,8 @@
        E = Exp->arg_end(); I != E; ++I) {
     BlkExprs.push_back(*I);
   }
-  CallExpr *CE = new CallExpr(PE, &BlkExprs[0], BlkExprs.size(), Exp->getType(), SourceLocation());
+  CallExpr *CE = new (Context) CallExpr(PE, &BlkExprs[0], BlkExprs.size(),
+                                        Exp->getType(), SourceLocation());
   return CE;
 }
 
@@ -3851,11 +3876,11 @@
 
 void RewriteObjC::RewriteBlockDeclRefExpr(BlockDeclRefExpr *BDRE) {
   // FIXME: Add more elaborate code generation required by the ABI.
-  Expr *DerefExpr = new UnaryOperator(BDRE, UnaryOperator::Deref,
+  Expr *DerefExpr = new (Context) UnaryOperator(BDRE, UnaryOperator::Deref,
                              Context->getPointerType(BDRE->getType()),
                              SourceLocation());
   // Need parens to enforce precedence.
-  ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), DerefExpr);
+  ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), DerefExpr);
   ReplaceStmt(BDRE, PE);
 }
 
@@ -3942,8 +3967,8 @@
   return false;
 }
 
-void RewriteObjC::GetExtentOfArgList(const char *Name, 
-                                       const char *&LParen, const char *&RParen) {
+void RewriteObjC::GetExtentOfArgList(const char *Name, const char *&LParen,
+                                     const char *&RParen) {
   const char *argPtr = strchr(Name, '(');
   assert((*argPtr == '(') && "Rewriter fuzzy parser confused");
   
@@ -4069,30 +4094,34 @@
   
   // Simulate a contructor call...
   FD = SynthBlockInitFunctionDecl(Tag.c_str());
-  DeclRefExpr *DRE = new DeclRefExpr(FD, FType, SourceLocation());
+  DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, FType, SourceLocation());
   
   llvm::SmallVector<Expr*, 4> InitExprs;
   
   // Initialize the block function.
   FD = SynthBlockInitFunctionDecl(Func.c_str());
-  DeclRefExpr *Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
-  CastExpr *castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg, 
-                                          Context->VoidPtrTy, SourceLocation(), SourceLocation());
+  DeclRefExpr *Arg = new (Context) DeclRefExpr(FD, FD->getType(),
+                                               SourceLocation());
+  CastExpr *castExpr = new (Context) CStyleCastExpr(Context->VoidPtrTy, Arg, 
+                                          Context->VoidPtrTy, SourceLocation(),
+                                                    SourceLocation());
   InitExprs.push_back(castExpr); 
   
   if (ImportedBlockDecls.size()) {
     std::string Buf = "__" + FuncName + "_block_copy_" + BlockNumber;
     FD = SynthBlockInitFunctionDecl(Buf.c_str());
-    Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
-    castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg, 
-                                  Context->VoidPtrTy, SourceLocation(), SourceLocation());
+    Arg = new (Context) DeclRefExpr(FD, FD->getType(), SourceLocation());
+    castExpr = new (Context) CStyleCastExpr(Context->VoidPtrTy, Arg, 
+                                  Context->VoidPtrTy, SourceLocation(),
+                                            SourceLocation());
     InitExprs.push_back(castExpr); 
     
     Buf = "__" + FuncName + "_block_dispose_" + BlockNumber;
     FD = SynthBlockInitFunctionDecl(Buf.c_str());
-    Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
-    castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg, 
-                                  Context->VoidPtrTy, SourceLocation(), SourceLocation());
+    Arg = new (Context) DeclRefExpr(FD, FD->getType(), SourceLocation());
+    castExpr = new (Context) CStyleCastExpr(Context->VoidPtrTy, Arg, 
+                                  Context->VoidPtrTy, SourceLocation(),
+                                            SourceLocation());
     InitExprs.push_back(castExpr); 
   }
   // Add initializers for any closure decl refs.
@@ -4104,15 +4133,16 @@
       if (isObjCType((*I)->getType())) {
         // FIXME: Conform to ABI ([[obj retain] autorelease]).
         FD = SynthBlockInitFunctionDecl((*I)->getNameAsCString());
-        Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
+        Exp = new (Context) DeclRefExpr(FD, FD->getType(), SourceLocation());
       } else if (isTopLevelBlockPointerType((*I)->getType())) {
         FD = SynthBlockInitFunctionDecl((*I)->getNameAsCString());
-        Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
-        Exp = new CStyleCastExpr(Context->VoidPtrTy, Arg, 
-                                 Context->VoidPtrTy, SourceLocation(), SourceLocation());
+        Arg = new (Context) DeclRefExpr(FD, FD->getType(), SourceLocation());
+        Exp = new (Context) CStyleCastExpr(Context->VoidPtrTy, Arg, 
+                                 Context->VoidPtrTy, SourceLocation(),
+                                           SourceLocation());
       } else {
         FD = SynthBlockInitFunctionDecl((*I)->getNameAsCString());
-        Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
+        Exp = new (Context) DeclRefExpr(FD, FD->getType(), SourceLocation());
       }
       InitExprs.push_back(Exp); 
     }
@@ -4120,19 +4150,20 @@
     for (llvm::SmallPtrSet<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), 
          E = BlockByRefDecls.end(); I != E; ++I) {
       FD = SynthBlockInitFunctionDecl((*I)->getNameAsCString());
-      Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
-      Exp = new UnaryOperator(Exp, UnaryOperator::AddrOf,
+      Exp = new (Context) DeclRefExpr(FD, FD->getType(), SourceLocation());
+      Exp = new (Context) UnaryOperator(Exp, UnaryOperator::AddrOf,
                               Context->getPointerType(Exp->getType()), 
                               SourceLocation());
       InitExprs.push_back(Exp); 
     }
   }
-  NewRep = new CallExpr(DRE, &InitExprs[0], InitExprs.size(),
+  NewRep = new (Context) CallExpr(DRE, &InitExprs[0], InitExprs.size(),
                         FType, SourceLocation());
-  NewRep = new UnaryOperator(NewRep, UnaryOperator::AddrOf,
+  NewRep = new (Context) UnaryOperator(NewRep, UnaryOperator::AddrOf,
                              Context->getPointerType(NewRep->getType()), 
                              SourceLocation());
-  NewRep = new CStyleCastExpr(FType, NewRep, FType, SourceLocation(), SourceLocation());
+  NewRep = new (Context) CStyleCastExpr(FType, NewRep, FType, SourceLocation(),
+                                        SourceLocation());
   BlockDeclRefs.clear();
   BlockByRefDecls.clear();
   BlockByCopyDecls.clear();
@@ -4363,7 +4394,7 @@
   }
 #if 0
   if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(S)) {
-    CastExpr *Replacement = new CastExpr(ICE->getType(), ICE->getSubExpr(), SourceLocation());
+    CastExpr *Replacement = new (Context) CastExpr(ICE->getType(), ICE->getSubExpr(), SourceLocation());
     // Get the new text.
     std::string SStr;
     llvm::raw_string_ostream Buf(SStr);

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Feb  6 19:47:29 2009
@@ -776,9 +776,7 @@
 public:
   CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, 
            SourceLocation rparenloc);
-  ~CallExpr() {
-    delete [] SubExprs;
-  }
+  ~CallExpr() { delete [] SubExprs; }
   
   const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
   Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
@@ -806,7 +804,7 @@
   /// setNumArgs - This changes the number of arguments present in this call.
   /// Any orphaned expressions are deleted by this, and any new operands are set
   /// to null.
-  void setNumArgs(unsigned NumArgs);
+  void setNumArgs(ASTContext& C, unsigned NumArgs);
   
   typedef ExprIterator arg_iterator;
   typedef ConstExprIterator const_arg_iterator;

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

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Feb  6 19:47:29 2009
@@ -22,6 +22,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/Bitcode/SerializationFwd.h"
+#include "clang/AST/ASTContext.h"
 #include <string>
 
 using llvm::dyn_cast_or_null;
@@ -102,6 +103,33 @@
 };
 private:
   const StmtClass sClass;
+
+  // Make vanilla 'new' and 'delete' illegal for Stmts.
+protected:
+  void* operator new(size_t bytes) throw() {
+    assert(0 && "Stmts cannot be allocated with regular 'new'.");
+    return 0;
+  }
+  void operator delete(void* data) throw() {
+    assert(0 && "Stmts cannot be released with regular 'delete'.");
+  }
+  
+public:
+  // Only allow allocation of Stmts using the allocator in ASTContext
+  // or by doing a placement new.  
+  void* operator new(size_t bytes, ASTContext& C,
+                     unsigned alignment = 16) throw() {
+    return ::operator new(bytes, C, alignment);
+  }
+  
+  void* operator new(size_t bytes, ASTContext* C,
+                     unsigned alignment = 16) throw() {
+    return ::operator new(bytes, *C, alignment);
+  }
+  
+  void* operator new(size_t bytes, void* mem) throw() {
+    return mem;
+  }
   
 protected:
   /// DestroyChildren - Invoked by destructors of subclasses of Stmt to
@@ -305,37 +333,52 @@
 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
 ///
 class CompoundStmt : public Stmt {
-  llvm::SmallVector<Stmt*, 16> Body;
+  Stmt** Body;
+  unsigned NumStmts;
   SourceLocation LBracLoc, RBracLoc;
 public:
-  CompoundStmt(Stmt **StmtStart, unsigned NumStmts, 
-               SourceLocation LB, SourceLocation RB)
-    : Stmt(CompoundStmtClass), Body(StmtStart, StmtStart+NumStmts),
-      LBracLoc(LB), RBracLoc(RB) {}
-    
-  bool body_empty() const { return Body.empty(); }
+  CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned numStmts, 
+                             SourceLocation LB, SourceLocation RB)
+  : Stmt(CompoundStmtClass), NumStmts(numStmts), LBracLoc(LB), RBracLoc(RB) {
+      if (NumStmts) {
+        Body = new (C) Stmt*[NumStmts];
+        memcpy(Body, StmtStart, numStmts * sizeof(*Body));
+      }
+      else
+        Body = 0;
+  }           
+  
+  bool body_empty() const { return NumStmts == 0; }
+  
+  typedef Stmt** body_iterator;
+  body_iterator body_begin() { return Body; }
+  body_iterator body_end() { return Body + NumStmts; }
+  Stmt *body_back() { return NumStmts ? Body[NumStmts-1] : 0; }
+
+  typedef Stmt* const * const_body_iterator;
+  const_body_iterator body_begin() const { return Body; }
+  const_body_iterator body_end() const { return Body + NumStmts; }
+  const Stmt *body_back() const { return NumStmts ? Body[NumStmts-1] : 0; }
+
+  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
+  reverse_body_iterator body_rbegin() {
+    return reverse_body_iterator(body_end());
+  }
+  reverse_body_iterator body_rend() {
+    return reverse_body_iterator(body_begin());
+  }
+
+  typedef std::reverse_iterator<const_body_iterator>
+          const_reverse_body_iterator;
+
+  const_reverse_body_iterator body_rbegin() const {
+    return const_reverse_body_iterator(body_end());
+  }
   
-  typedef llvm::SmallVector<Stmt*, 16>::iterator body_iterator;
-  body_iterator body_begin() { return Body.begin(); }
-  body_iterator body_end() { return Body.end(); }
-  Stmt *body_back() { return Body.back(); }
-
-  typedef llvm::SmallVector<Stmt*, 16>::const_iterator const_body_iterator;
-  const_body_iterator body_begin() const { return Body.begin(); }
-  const_body_iterator body_end() const { return Body.end(); }
-  const Stmt *body_back() const { return Body.back(); }
-
-  typedef llvm::SmallVector<Stmt*, 16>::reverse_iterator reverse_body_iterator;
-  reverse_body_iterator body_rbegin() { return Body.rbegin(); }
-  reverse_body_iterator body_rend() { return Body.rend(); }
-
-  typedef llvm::SmallVector<Stmt*, 16>::const_reverse_iterator 
-    const_reverse_body_iterator;
-  const_reverse_body_iterator body_rbegin() const { return Body.rbegin(); }
-  const_reverse_body_iterator body_rend() const { return Body.rend(); }
+  const_reverse_body_iterator body_rend() const {
+    return const_reverse_body_iterator(body_begin());
+  }
     
-  void push_back(Stmt *S) { Body.push_back(S); }
-  
   virtual SourceRange getSourceRange() const { 
     return SourceRange(LBracLoc, RBracLoc); 
   }

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

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Feb  6 19:47:29 2009
@@ -54,8 +54,8 @@
 }
 
 void StringLiteral::Destroy(ASTContext &C) {
-  C.Deallocate(const_cast<char*>(StrData));
   this->~StringLiteral();
+  C.Deallocate(const_cast<char*>(StrData));
 }
 
 bool UnaryOperator::isPostfix(Opcode Op) {
@@ -104,8 +104,8 @@
 // Postfix Operators.
 //===----------------------------------------------------------------------===//
 
-CallExpr::CallExpr(StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 
-                   QualType t, SourceLocation rparenloc)
+CallExpr::CallExpr(StmtClass SC, Expr *fn, Expr **args,
+                   unsigned numargs, QualType t, SourceLocation rparenloc)
   : Expr(SC, t, 
          fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs),
          fn->isValueDependent() || hasAnyValueDependentArguments(args, numargs)),
@@ -133,14 +133,14 @@
 /// setNumArgs - This changes the number of arguments present in this call.
 /// Any orphaned expressions are deleted by this, and any new operands are set
 /// to null.
-void CallExpr::setNumArgs(unsigned NumArgs) {
+void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) {
   // No change, just return.
   if (NumArgs == getNumArgs()) return;
   
   // If shrinking # arguments, just delete the extras and forgot them.
   if (NumArgs < getNumArgs()) {
     for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i)
-      delete getArg(i);
+      getArg(i)->Destroy(C);
     this->NumArgs = NumArgs;
     return;
   }
@@ -154,7 +154,7 @@
   for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
     NewSubExprs[i] = 0;
   
-  delete[] SubExprs;
+  delete [] SubExprs;
   SubExprs = NewSubExprs;
   this->NumArgs = NumArgs;
 }
@@ -1391,10 +1391,10 @@
   // will iterate over the size expression. However, this expression belongs
   // to the type, not to this, so we don't want to delete it.
   // We still want to delete this expression.
-  // FIXME: Same as in Stmt::Destroy - will be eventually in ASTContext's
-  // pool allocator.
-  if (isArgumentType())
-    delete this;
+  if (isArgumentType()) {
+    this->~SizeOfAlignOfExpr();
+    C.Deallocate(this);
+  }
   else
     Expr::Destroy(C);
 }

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

==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Fri Feb  6 19:47:29 2009
@@ -20,10 +20,10 @@
   // FIXME: Cannot destroy the decl here, because it is linked into the
   // DeclContext's chain.
   //getVarDecl()->Destroy(C);
-  delete this;
+  this->~CXXConditionDeclExpr();
+  C.Deallocate(this);
 }
 
-
 //===----------------------------------------------------------------------===//
 //  Child Iterators for iterating over subexpressions/substatements
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Fri Feb  6 19:47:29 2009
@@ -219,7 +219,7 @@
 
 // CompoundStmt
 Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; }
-Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+Body.size(); }
+Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; }
 
 // CaseStmt
 Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; }

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

==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Fri Feb  6 19:47:29 2009
@@ -483,7 +483,8 @@
   S.EmitOwnedPtr(Init);
 }
 
-CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D, ASTContext& C) {
+CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D,
+                                                     ASTContext& C) {
   QualType Q = QualType::ReadVal(D);
   SourceLocation L = SourceLocation::ReadVal(D);
   bool fileScope = D.ReadBool();
@@ -495,10 +496,8 @@
 void CompoundStmt::EmitImpl(Serializer& S) const {
   S.Emit(LBracLoc);
   S.Emit(RBracLoc);
-  S.Emit(Body.size());
-  
-  for (const_body_iterator I=body_begin(), E=body_end(); I!=E; ++I)
-    S.EmitOwnedPtr(*I);
+  S.Emit(NumStmts);
+  if (NumStmts) S.BatchEmitOwnedPtrs(NumStmts, &Body[0]);
 }
 
 CompoundStmt* CompoundStmt::CreateImpl(Deserializer& D, ASTContext& C) {
@@ -507,13 +506,15 @@
   unsigned size = D.ReadInt();
   
   CompoundStmt* stmt = new (C, llvm::alignof<CompoundStmt>())
-    CompoundStmt(NULL, 0, LB, RB);
-  
-  stmt->Body.reserve(size);
-  
-  for (unsigned i = 0; i < size; ++i)
-    stmt->Body.push_back(D.ReadOwnedPtr<Stmt>(C));
+    CompoundStmt(C, NULL, 0, LB, RB);
+
+  stmt->NumStmts = size;
   
+  if (size) {
+    stmt->Body = new (C) Stmt*[size];
+    D.BatchReadOwnedPtrs(size, &stmt->Body[0], C);
+  }
+
   return stmt;
 }
 
@@ -1306,7 +1307,7 @@
   Expr *B = D.ReadOwnedPtr<Expr>(C);
   IdentifierInfo *A = D.ReadPtr<IdentifierInfo>();
   SourceLocation AL = SourceLocation::ReadVal(D);
-  return new ExtVectorElementExpr(T, B, *A, AL);
+  return new (C) ExtVectorElementExpr(T, B, *A, AL);
 }
 
 void BlockExpr::EmitImpl(Serializer& S) const {

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Fri Feb  6 19:47:29 2009
@@ -183,7 +183,7 @@
     ImpCast->setType(Ty);
     ImpCast->setLvalueCast(isLvalue);
   } else 
-    Expr = new ImplicitCastExpr(Ty, Expr, isLvalue);
+    Expr = new (Context) ImplicitCastExpr(Ty, Expr, isLvalue);
 }
 
 void Sema::DeleteExpr(ExprTy *E) {

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Feb  6 19:47:29 2009
@@ -1970,7 +1970,7 @@
   
   BlockDecl *TheDecl;
   
-  /// TheScope - This is the scope for the block itself, which contains
+  /// TheScope - This is the scope for the block itself, which containsfile://localhost/Volumes/Data/Users/kremenek/llvm/tools/clang
   /// arguments etc.
   Scope *TheScope;
   
@@ -1982,8 +1982,23 @@
   /// to the outer block.
   BlockSemaInfo *PrevBlockInfo;
 };
-
-
+  
+//===--------------------------------------------------------------------===//
+// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
+template <typename T>
+class ExprOwningPtr : public Action::ExprArg {
+public:
+  ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
+  
+  void reset(T* p) { Action::ExprArg::operator=(p); }
+  T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
+  T* take() { return static_cast<T*>(Action::ExprArg::take()); }
+  T* release() { return take(); }
+  
+  T& operator*() const { return *get(); }
+  T* operator->() const { return get(); }
+};
+  
 }  // end namespace clang
 
 #endif

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Feb  6 19:47:29 2009
@@ -306,9 +306,10 @@
     TheCall->setArg(i, 0);
   }
 
-  return Owned(new ShuffleVectorExpr(exprs.begin(), numElements+2, FAType,
-                                     TheCall->getCallee()->getLocStart(),
-                                     TheCall->getRParenLoc()));
+  return Owned(new (Context) ShuffleVectorExpr(exprs.begin(), numElements+2,
+                                            FAType,
+                                            TheCall->getCallee()->getLocStart(),
+                                            TheCall->getRParenLoc()));
 }
 
 /// SemaBuiltinPrefetch - Handle __builtin_prefetch.

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Feb  6 19:47:29 2009
@@ -2260,7 +2260,7 @@
   // If there is no declaration, there was an error parsing it.  Just ignore
   // the initializer.
   if (RealDecl == 0) {
-    delete Init;
+    Init->Destroy(Context);
     return;
   }
   
@@ -2697,8 +2697,10 @@
     assert(FD == getCurFunctionDecl() && "Function parsing confused");
   } else if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
     MD->setBody((Stmt*)Body);
-  } else
+  } else {
+    Body->Destroy(Context);
     return 0;
+  }
   PopDeclContext();
   // Verify and clean out per-function state.
   
@@ -2717,11 +2719,17 @@
       // the function body so that they aren't leaked and that the AST is well
       // formed.
       if (Body) {
-        L->setSubStmt(new NullStmt(L->getIdentLoc()));
-        cast<CompoundStmt>(Body)->push_back(L);
+#if 0
+        // FIXME: Why do this?  Having a 'push_back' in CompoundStmt is ugly,
+        // and the AST is malformed anyway.  We should just blow away 'L'.
+        L->setSubStmt(new (Context) NullStmt(L->getIdentLoc()));
+        cast<CompoundStmt>(Body)->push_back(L);        
+#else
+        L->Destroy(Context);
+#endif
       } else {
         // The whole function wasn't parsed correctly, just delete this.
-        delete L;
+        L->Destroy(Context);
       }
     }
   }
@@ -3516,7 +3524,7 @@
       else
         Diag(IdLoc, diag::err_redefinition) << Id;
       Diag(PrevDecl->getLocation(), diag::note_previous_definition);
-      delete Val;
+      Val->Destroy(Context);
       return 0;
     }
   }
@@ -3530,7 +3538,7 @@
     // C99 6.7.2.2p2: Make sure we have an integer constant expression.
     SourceLocation ExpLoc;
     if (VerifyIntegerConstantExpression(Val, &EnumVal)) {
-      delete Val;
+      Val->Destroy(Context);
       Val = 0;  // Just forget about it.
     } else {
       EltTy = Val->getType();
@@ -3721,8 +3729,8 @@
     
     // Adjust the Expr initializer and type.
     if (ECD->getInitExpr())
-      ECD->setInitExpr(new ImplicitCastExpr(NewTy, ECD->getInitExpr(), 
-                                            /*isLvalue=*/false));
+      ECD->setInitExpr(new (Context) ImplicitCastExpr(NewTy, ECD->getInitExpr(), 
+                                                      /*isLvalue=*/false));
     if (getLangOptions().CPlusPlus)
       // C++ [dcl.enum]p4: Following the closing brace of an
       // enum-specifier, each enumerator has the type of its
@@ -3756,7 +3764,7 @@
         !Val.isPowerOf2() ||
         Val.getZExtValue() > 16) {
       Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
-      delete Alignment;
+      Alignment->Destroy(Context);
       return; // Ignore
     }
 

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Feb  6 19:47:29 2009
@@ -107,7 +107,7 @@
 Sema::ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc, 
                                 ExprTy *defarg) {
   ParmVarDecl *Param = (ParmVarDecl *)param;
-  llvm::OwningPtr<Expr> DefaultArg((Expr *)defarg);
+  ExprOwningPtr<Expr> DefaultArg(this, (Expr *)defarg);
   QualType ParamType = Param->getType();
 
   // Default arguments are only permitted in C++
@@ -1503,7 +1503,7 @@
   // the initializer.
   if (RealDecl == 0) {
     for (unsigned i = 0; i != NumExprs; ++i)
-      delete static_cast<Expr *>(ExprTys[i]);
+      static_cast<Expr *>(ExprTys[i])->Destroy(Context);
     return;
   }
   

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Feb  6 19:47:29 2009
@@ -454,8 +454,7 @@
   if (BaseObject) {
     // BaseObject is an anonymous struct/union variable (and is,
     // therefore, not part of another non-anonymous record).
-    delete BaseObjectExpr;
-
+    if (BaseObjectExpr) BaseObjectExpr->Destroy(Context);
     BaseObjectExpr = new (Context) DeclRefExpr(BaseObject,BaseObject->getType(),
                                      SourceLocation());
     ExtraQuals 
@@ -1770,7 +1769,7 @@
         << Fn->getType()->isBlockPointerType() << Fn->getSourceRange();
     // Use default arguments for missing arguments
     NumArgsToCheck = NumArgsInProto;
-    Call->setNumArgs(NumArgsInProto);
+    Call->setNumArgs(Context, NumArgsInProto);
   }
 
   // If too many are passed and not variadic, error on the extras and drop
@@ -1783,7 +1782,7 @@
         << SourceRange(Args[NumArgsInProto]->getLocStart(),
                        Args[NumArgs-1]->getLocEnd());
       // This deletes the extra arguments.
-      Call->setNumArgs(NumArgsInProto);
+      Call->setNumArgs(Context, NumArgsInProto);
       Invalid = true;
     }
     NumArgsToCheck = NumArgsInProto;
@@ -1945,7 +1944,7 @@
   // of arguments and function on error.
   // FIXME: Except that llvm::OwningPtr uses delete, when it really must be
   // Destroy(), or nothing gets cleaned up.
-  llvm::OwningPtr<CallExpr> TheCall(new (Context) CallExpr(Fn, Args, NumArgs,
+  ExprOwningPtr<CallExpr> TheCall(this, new (Context) CallExpr(Fn, Args,NumArgs,
                                                  Context.BoolTy, RParenLoc));
 
   const FunctionType *FuncT;
@@ -4154,7 +4153,7 @@
       // Offset of an array sub-field.  TODO: Should we allow vector elements?
       const ArrayType *AT = Context.getAsArrayType(Res->getType());
       if (!AT) {
-        delete Res;
+        Res->Destroy(Context);
         return Diag(OC.LocEnd, diag::err_offsetof_array_type) << Res->getType();
       }
       
@@ -4173,7 +4172,7 @@
     
     const RecordType *RC = Res->getType()->getAsRecordType();
     if (!RC) {
-      delete Res;
+      Res->Destroy(Context);
       return Diag(OC.LocEnd, diag::err_offsetof_record_type) << Res->getType();
     }
       
@@ -4336,7 +4335,7 @@
                                           Scope *CurScope) {
   // Ensure that CurBlock is deleted.
   llvm::OwningPtr<BlockSemaInfo> BSI(CurBlock);
-  llvm::OwningPtr<CompoundStmt> Body(static_cast<CompoundStmt*>(body));
+  ExprOwningPtr<CompoundStmt> Body(this, static_cast<CompoundStmt*>(body));
 
   PopDeclContext();
 

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Feb  6 19:47:29 2009
@@ -70,8 +70,8 @@
 
   QualType TypeInfoType = Context.getTypeDeclType(TypeInfoRecordDecl);
 
-  return new CXXTypeidExpr(isType, TyOrExpr, TypeInfoType.withConst(),
-                           SourceRange(OpLoc, RParenLoc));
+  return new (Context) CXXTypeidExpr(isType, TyOrExpr, TypeInfoType.withConst(),
+                                     SourceRange(OpLoc, RParenLoc));
 }
 
 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
@@ -79,13 +79,13 @@
 Sema::ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
   assert((Kind == tok::kw_true || Kind == tok::kw_false) &&
          "Unknown C++ Boolean value!");
-  return new CXXBoolLiteralExpr(Kind == tok::kw_true, Context.BoolTy, OpLoc);
+  return new (Context) CXXBoolLiteralExpr(Kind == tok::kw_true, Context.BoolTy, OpLoc);
 }
 
 /// ActOnCXXThrow - Parse throw expressions.
 Action::ExprResult
 Sema::ActOnCXXThrow(SourceLocation OpLoc, ExprTy *E) {
-  return new CXXThrowExpr((Expr*)E, Context.VoidTy, OpLoc);
+  return new (Context) CXXThrowExpr((Expr*)E, Context.VoidTy, OpLoc);
 }
 
 Action::ExprResult Sema::ActOnCXXThis(SourceLocation ThisLoc) {
@@ -100,7 +100,7 @@
 
   if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext))
     if (MD->isInstance())
-      return new CXXThisExpr(ThisLoc, MD->getThisType(Context));
+      return new (Context) CXXThisExpr(ThisLoc, MD->getThisType(Context));
 
   return Diag(ThisLoc, diag::err_invalid_this_use);
 }
@@ -129,8 +129,8 @@
   if (NumExprs == 1) {
     if (CheckCastTypes(TypeRange, Ty, Exprs[0]))
       return true;
-    return new CXXFunctionalCastExpr(Ty.getNonReferenceType(), Ty, TyBeginLoc, 
-                                     Exprs[0], RParenLoc);
+    return new (Context) CXXFunctionalCastExpr(Ty.getNonReferenceType(), Ty,
+                                               TyBeginLoc, Exprs[0], RParenLoc);
   }
 
   if (const RecordType *RT = Ty->getAsRecordType()) {
@@ -148,7 +148,7 @@
       if (!Constructor)
         return true;
 
-      return new CXXTemporaryObjectExpr(Constructor, Ty, TyBeginLoc, 
+      return new (Context) CXXTemporaryObjectExpr(Constructor, Ty, TyBeginLoc, 
                                         Exprs, NumExprs, RParenLoc);
     }
 
@@ -178,7 +178,7 @@
                              diag::err_invalid_incomplete_type_use, FullRange))
     return true;
 
-  return new CXXZeroInitValueExpr(Ty, TyBeginLoc, RParenLoc);
+  return new (Context) CXXZeroInitValueExpr(Ty, TyBeginLoc, RParenLoc);
 }
 
 
@@ -312,8 +312,8 @@
 
   // FIXME: Also check that the destructor is accessible. (C++ 5.3.4p16)
 
-  return new CXXNewExpr(UseGlobal, OperatorNew, PlaceArgs, NumPlaceArgs,
-                        ParenTypeId, ArraySize, Constructor, Init,
+  return new (Context) CXXNewExpr(UseGlobal, OperatorNew, PlaceArgs,
+                        NumPlaceArgs, ParenTypeId, ArraySize, Constructor, Init,
                         ConsArgs, NumConsArgs, OperatorDelete, ResultType,
                         StartLoc, Init ? ConstructorRParen : SourceLocation());
 }
@@ -384,7 +384,7 @@
   // We don't care about the actual value of this argument.
   // FIXME: Should the Sema create the expression and embed it in the syntax
   // tree? Or should the consumer just recalculate the value?
-  AllocArgs[0] = new IntegerLiteral(llvm::APInt::getNullValue(
+  AllocArgs[0] = new (Context) IntegerLiteral(llvm::APInt::getNullValue(
                                         Context.Target.getPointerWidth(0)),
                                     Context.getSizeType(),
                                     SourceLocation());
@@ -533,7 +533,7 @@
       // FIXME: Do we need to check for default arguments here?
       FunctionDecl *Func = cast<FunctionDecl>(*Alloc);
       if (Func->getNumParams() == 1 &&
-          Context.getCanonicalType(Func->getParamDecl(0)->getType()) == Argument)
+          Context.getCanonicalType(Func->getParamDecl(0)->getType())==Argument)
         return;
     }
   }
@@ -594,8 +594,8 @@
   // along.
   // FIXME: Check access and ambiguity of operator delete and destructor.
 
-  return new CXXDeleteExpr(Context.VoidTy, UseGlobal, ArrayForm, 0, Ex,
-                           StartLoc);
+  return new (Context) CXXDeleteExpr(Context.VoidTy, UseGlobal, ArrayForm, 0,
+                                     Ex, StartLoc);
 }
 
 
@@ -648,7 +648,7 @@
   if (VarDecl *VD = dyn_cast<VarDecl>((Decl *)Dcl))
     VD->setDeclaredInCondition(true);
 
-  return new CXXConditionDeclExpr(StartLoc, EqualLoc,
+  return new (Context) CXXConditionDeclExpr(StartLoc, EqualLoc,
                                        cast<VarDecl>(static_cast<Decl *>(Dcl)));
 }
 
@@ -879,7 +879,7 @@
   // There is no point in eagerly computing the value. The traits are designed
   // to be used from type trait templates, so Ty will be a template parameter
   // 99% of the time.
-  return Owned(new UnaryTypeTraitExpr(KWLoc, OTT,
+  return Owned(new (Context) UnaryTypeTraitExpr(KWLoc, OTT,
                                       QualType::getFromOpaquePtr(Ty),
                                       RParen, Context.BoolTy));
 }

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Feb  6 19:47:29 2009
@@ -38,7 +38,7 @@
         isWide = true;
       memcpy(p, S->getStrData(), S->getByteLength());
       p += S->getByteLength();
-      delete S;
+      S->Destroy(Context);
     }
     S = new (Context, 8) StringLiteral(Context, strBuf, Length, isWide,
                                        Context.getPointerType(Context.CharTy),
@@ -65,7 +65,7 @@
   } else {
     t = Context.getPointerType(t);
   }
-  return new ObjCStringLiteral(S, t, AtLoc);
+  return new (Context) ObjCStringLiteral(S, t, AtLoc);
 }
 
 Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
@@ -76,7 +76,7 @@
   QualType EncodedType = QualType::getFromOpaquePtr(Ty);
 
   QualType t = Context.getPointerType(Context.CharTy);
-  return new ObjCEncodeExpr(t, EncodedType, AtLoc, RParenLoc);
+  return new (Context) ObjCEncodeExpr(t, EncodedType, AtLoc, RParenLoc);
 }
 
 Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
@@ -85,7 +85,7 @@
                                                    SourceLocation LParenLoc,
                                                    SourceLocation RParenLoc) {
   QualType t = Context.getObjCSelType();
-  return new ObjCSelectorExpr(t, Sel, AtLoc, RParenLoc);
+  return new (Context) ObjCSelectorExpr(t, Sel, AtLoc, RParenLoc);
 }
 
 Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,
@@ -103,7 +103,7 @@
   if (t.isNull())
     return true;
   t = Context.getPointerType(t);
-  return new ObjCProtocolExpr(t, PDecl, AtLoc, RParenLoc);
+  return new (Context) ObjCProtocolExpr(t, PDecl, AtLoc, RParenLoc);
 }
 
 bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, 
@@ -199,7 +199,8 @@
       if (getCurMethodDecl()->isInstanceMethod()) {
         QualType superTy = Context.getObjCInterfaceType(ClassDecl);
         superTy = Context.getPointerType(superTy);
-        ExprResult ReceiverExpr = new ObjCSuperExpr(SourceLocation(), superTy);
+        ExprResult ReceiverExpr = new (Context) ObjCSuperExpr(SourceLocation(),
+                                                              superTy);
         // We are really in an instance method, redirect.
         return ActOnInstanceMessage(ReceiverExpr.get(), Sel, lbrac, rbrac,
                                     Args, NumArgs);
@@ -212,8 +213,8 @@
       NamedDecl *SuperDecl = LookupName(S, receiverName, LookupOrdinaryName);
       ValueDecl *VD = dyn_cast_or_null<ValueDecl>(SuperDecl);
       if (VD) {
-        ExprResult ReceiverExpr = new DeclRefExpr(VD, VD->getType(), 
-                                                  receiverLoc);
+        ExprResult ReceiverExpr = new (Context) DeclRefExpr(VD, VD->getType(), 
+                                                            receiverLoc);
         // We are really in an instance method, redirect.
         return ActOnInstanceMessage(ReceiverExpr.get(), Sel, lbrac, rbrac,
                                     Args, NumArgs);
@@ -277,11 +278,11 @@
   // For now, we simply pass the "super" identifier through (which isn't
   // consistent with instance methods.
   if (isSuper)
-    return new ObjCMessageExpr(receiverName, Sel, returnType, Method,
-                               lbrac, rbrac, ArgExprs, NumArgs);
+    return new (Context) ObjCMessageExpr(receiverName, Sel, returnType, Method,
+                                         lbrac, rbrac, ArgExprs, NumArgs);
   else
-    return new ObjCMessageExpr(ClassDecl, Sel, returnType, Method,
-                               lbrac, rbrac, ArgExprs, NumArgs);
+    return new (Context) ObjCMessageExpr(ClassDecl, Sel, returnType, Method,
+                                         lbrac, rbrac, ArgExprs, NumArgs);
 }
 
 // ActOnInstanceMessage - used for both unary and keyword messages.
@@ -312,8 +313,8 @@
     if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
                                   lbrac, rbrac, returnType))
       return true;
-    return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
-                               ArgExprs, NumArgs);
+    return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
+                                         rbrac, ArgExprs, NumArgs);
   }
 
   // Handle messages to id.
@@ -326,8 +327,8 @@
     if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, 
                                   lbrac, rbrac, returnType))
       return true;
-    return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
-                               ArgExprs, NumArgs);
+    return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
+                                         rbrac, ArgExprs, NumArgs);
   }
   
   // Handle messages to Class.
@@ -348,8 +349,8 @@
     if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
                                   lbrac, rbrac, returnType))
       return true;
-    return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
-                               ArgExprs, NumArgs);
+    return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
+                                         rbrac, ArgExprs, NumArgs);
   }
   
   ObjCMethodDecl *Method = 0;
@@ -411,8 +412,8 @@
   if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,
                                 lbrac, rbrac, returnType))
     return true;
-  return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
-                             ArgExprs, NumArgs);
+  return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
+                                       rbrac, ArgExprs, NumArgs);
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Sema/SemaNamedCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaNamedCast.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaNamedCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaNamedCast.cpp Fri Feb  6 19:47:29 2009
@@ -76,26 +76,26 @@
   case tok::kw_const_cast:
     if (!TypeDependent)
       CheckConstCast(*this, Ex, DestType, OpRange, DestRange);
-    return new CXXConstCastExpr(DestType.getNonReferenceType(), Ex, 
-                                DestType, OpLoc);
+    return new (Context) CXXConstCastExpr(DestType.getNonReferenceType(), Ex, 
+                                          DestType, OpLoc);
 
   case tok::kw_dynamic_cast:
     if (!TypeDependent)
       CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange);
-    return new CXXDynamicCastExpr(DestType.getNonReferenceType(), Ex, 
-                                  DestType, OpLoc);
+    return new (Context)CXXDynamicCastExpr(DestType.getNonReferenceType(), Ex, 
+                                           DestType, OpLoc);
 
   case tok::kw_reinterpret_cast:
     if (!TypeDependent)
       CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
-    return new CXXReinterpretCastExpr(DestType.getNonReferenceType(), Ex, 
-                                      DestType, OpLoc);
+    return new (Context) CXXReinterpretCastExpr(DestType.getNonReferenceType(),
+                                                Ex, DestType, OpLoc);
 
   case tok::kw_static_cast:
     if (!TypeDependent)
       CheckStaticCast(*this, Ex, DestType, OpRange);
-    return new CXXStaticCastExpr(DestType.getNonReferenceType(), Ex, 
-                                 DestType, OpLoc);
+    return new (Context) CXXStaticCastExpr(DestType.getNonReferenceType(), Ex, 
+                                           DestType, OpLoc);
   }
 
   return true;

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Feb  6 19:47:29 2009
@@ -3600,9 +3600,9 @@
   // Extract the object argument.
   Expr *ObjectArg = MemExpr->getBase();
   if (MemExpr->isArrow())
-    ObjectArg = new UnaryOperator(ObjectArg, UnaryOperator::Deref,
-                      ObjectArg->getType()->getAsPointerType()->getPointeeType(),
-                      SourceLocation());
+    ObjectArg = new (Context) UnaryOperator(ObjectArg, UnaryOperator::Deref,
+                     ObjectArg->getType()->getAsPointerType()->getPointeeType(),
+                     SourceLocation());
   CXXMethodDecl *Method = 0;
   if (OverloadedFunctionDecl *Ovl 
         = dyn_cast<OverloadedFunctionDecl>(MemExpr->getMemberDecl())) {
@@ -3647,8 +3647,8 @@
   }
 
   assert(Method && "Member call to something that isn't a method?");
-  llvm::OwningPtr<CXXMemberCallExpr> 
-    TheCall(new CXXMemberCallExpr(MemExpr, Args, NumArgs, 
+  ExprOwningPtr<CXXMemberCallExpr> 
+    TheCall(this, new (Context) CXXMemberCallExpr(MemExpr, Args, NumArgs, 
                                   Method->getResultType().getNonReferenceType(),
                                   RParenLoc));
 
@@ -3759,9 +3759,9 @@
   if (Best == CandidateSet.end()) {
     // We had an error; delete all of the subexpressions and return
     // the error.
-    delete Object;
+    Object->Destroy(Context);
     for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx)
-      delete Args[ArgIdx];
+      Args[ArgIdx]->Destroy(Context);
     return true;
   }
 
@@ -3807,22 +3807,23 @@
   for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx)
     MethodArgs[ArgIdx + 1] = Args[ArgIdx];
       
-  Expr *NewFn = new DeclRefExpr(Method, Method->getType(), 
-                                SourceLocation());
+  Expr *NewFn = new (Context) DeclRefExpr(Method, Method->getType(), 
+                                          SourceLocation());
   UsualUnaryConversions(NewFn);
 
   // Once we've built TheCall, all of the expressions are properly
   // owned.
   QualType ResultTy = Method->getResultType().getNonReferenceType();
-  llvm::OwningPtr<CXXOperatorCallExpr> 
-    TheCall(new CXXOperatorCallExpr(NewFn, MethodArgs, NumArgs + 1,
-                                    ResultTy, RParenLoc));
+  ExprOwningPtr<CXXOperatorCallExpr> 
+    TheCall(this, new (Context) CXXOperatorCallExpr(NewFn, MethodArgs,
+                                                    NumArgs + 1,
+                                                    ResultTy, RParenLoc));
   delete [] MethodArgs;
 
   // We may have default arguments. If so, we need to allocate more
   // slots in the call for them.
   if (NumArgs < NumArgsInProto)
-    TheCall->setNumArgs(NumArgsInProto + 1);
+    TheCall->setNumArgs(Context, NumArgsInProto + 1);
   else if (NumArgs > NumArgsInProto)
     NumArgsToCheck = NumArgsInProto;
 
@@ -3842,7 +3843,7 @@
       if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
         return true;
     } else {
-      Arg = new CXXDefaultArgExpr(Method->getParamDecl(i));
+      Arg = new (Context) CXXDefaultArgExpr(Method->getParamDecl(i));
     }
 
     TheCall->setArg(i + 1, Arg);
@@ -3888,7 +3889,7 @@
     AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Base, 0, 0, CandidateSet,
                        /*SuppressUserConversions=*/false);
 
-  llvm::OwningPtr<Expr> BasePtr(Base);
+  ExprOwningPtr<Expr> BasePtr(this, Base);
 
   // Perform overload resolution.
   OverloadCandidateSet::iterator Best;
@@ -3924,9 +3925,10 @@
   BasePtr.take();
 
   // Build the operator call.
-  Expr *FnExpr = new DeclRefExpr(Method, Method->getType(), SourceLocation());
+  Expr *FnExpr = new (Context) DeclRefExpr(Method, Method->getType(),
+                                           SourceLocation());
   UsualUnaryConversions(FnExpr);
-  Base = new CXXOperatorCallExpr(FnExpr, &Base, 1, 
+  Base = new (Context) CXXOperatorCallExpr(FnExpr, &Base, 1, 
                                  Method->getResultType().getNonReferenceType(),
                                  OpLoc);
   return ActOnMemberReferenceExpr(S, ExprArg(*this, Base), OpLoc, tok::arrow,

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Feb  6 19:47:29 2009
@@ -16,6 +16,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/Basic/TargetInfo.h"
 using namespace clang;
 
@@ -33,7 +34,7 @@
 
 
 Sema::OwningStmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) {
-  return Owned(new NullStmt(SemiLoc));
+  return Owned(new (Context) NullStmt(SemiLoc));
 }
 
 Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclTy *decl,
@@ -58,11 +59,11 @@
 
   if (decls.size() == 1) {
     DeclGroupOwningRef DG(*decls.begin());                      
-    return Owned(new DeclStmt(DG, StartLoc, EndLoc));
+    return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc));
   }
   else {
     DeclGroupOwningRef DG(DeclGroup::Create(Context, decls.size(), &decls[0]));
-    return Owned(new DeclStmt(DG, StartLoc, EndLoc));
+    return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc));
   }
 }
 
@@ -115,7 +116,7 @@
       Diag(E->getExprLoc(), diag::warn_unused_expr) << E->getSourceRange();
   }
 
-  return Owned(new CompoundStmt(Elts, NumElts, L, R));
+  return Owned(new (Context) CompoundStmt(Context, Elts, NumElts, L, R));
 }
 
 Action::OwningStmtResult
@@ -148,7 +149,7 @@
   // Only now release the smart pointers.
   lhsval.release();
   rhsval.release();
-  CaseStmt *CS = new CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc);
+  CaseStmt *CS = new (Context) CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc);
   SwitchStack.back()->addSwitchCase(CS);
   return Owned(CS);
 }
@@ -163,7 +164,7 @@
     return Owned(SubStmt);
   }
 
-  DefaultStmt *DS = new DefaultStmt(DefaultLoc, SubStmt);
+  DefaultStmt *DS = new (Context) DefaultStmt(DefaultLoc, SubStmt);
   SwitchStack.back()->addSwitchCase(DS);
   return Owned(DS);
 }
@@ -177,7 +178,7 @@
 
   // If not forward referenced or defined already, just create a new LabelStmt.
   if (LabelDecl == 0)
-    return Owned(LabelDecl = new LabelStmt(IdentLoc, II, SubStmt));
+    return Owned(LabelDecl = new (Context) LabelStmt(IdentLoc, II, SubStmt));
 
   assert(LabelDecl->getID() == II && "Label mismatch!");
 
@@ -228,7 +229,8 @@
   }
 
   CondVal.release();
-  return Owned(new IfStmt(IfLoc, condExpr, thenStmt, (Stmt*)ElseVal.release()));
+  return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt,
+                                    (Stmt*)ElseVal.release()));
 }
 
 Action::OwningStmtResult
@@ -260,7 +262,7 @@
     UsualUnaryConversions(Cond);
   }
 
-  SwitchStmt *SS = new SwitchStmt(Cond);
+  SwitchStmt *SS = new (Context) SwitchStmt(Cond);
   SwitchStack.push_back(SS);
   return Owned(SS);
 }
@@ -549,7 +551,8 @@
       << condType << condExpr->getSourceRange());
 
   Cond.release();
-  return Owned(new WhileStmt(condExpr, (Stmt*)Body.release(), WhileLoc));
+  return Owned(new (Context) WhileStmt(condExpr, (Stmt*)Body.release(),
+                                       WhileLoc));
 }
 
 Action::OwningStmtResult
@@ -570,7 +573,7 @@
       << condType << condExpr->getSourceRange());
 
   Cond.release();
-  return Owned(new DoStmt((Stmt*)Body.release(), condExpr, DoLoc));
+  return Owned(new (Context) DoStmt((Stmt*)Body.release(), condExpr, DoLoc));
 }
 
 Action::OwningStmtResult
@@ -614,7 +617,7 @@
   second.release();
   third.release();
   body.release();
-  return Owned(new ForStmt(First, Second, Third, Body, ForLoc));
+  return Owned(new (Context) ForStmt(First, Second, Third, Body, ForLoc));
 }
 
 Action::OwningStmtResult
@@ -665,8 +668,8 @@
   first.release();
   second.release();
   body.release();
-  return Owned(new ObjCForCollectionStmt(First, Second, Body,
-                                         ForLoc, RParenLoc));
+  return Owned(new (Context) ObjCForCollectionStmt(First, Second, Body,
+                                                   ForLoc, RParenLoc));
 }
 
 Action::OwningStmtResult
@@ -681,9 +684,9 @@
 
   // If we haven't seen this label yet, create a forward reference.
   if (LabelDecl == 0)
-    LabelDecl = new LabelStmt(LabelLoc, LabelII, 0);
+    LabelDecl = new (Context) LabelStmt(LabelLoc, LabelII, 0);
 
-  return Owned(new GotoStmt(LabelDecl, GotoLoc, LabelLoc));
+  return Owned(new (Context) GotoStmt(LabelDecl, GotoLoc, LabelLoc));
 }
 
 Action::OwningStmtResult
@@ -691,7 +694,7 @@
                             ExprArg DestExp) {
   // FIXME: Verify that the operand is convertible to void*.
 
-  return Owned(new IndirectGotoStmt((Expr*)DestExp.release()));
+  return Owned(new (Context) IndirectGotoStmt((Expr*)DestExp.release()));
 }
 
 Action::OwningStmtResult
@@ -702,7 +705,7 @@
     return StmtError(Diag(ContinueLoc, diag::err_continue_not_in_loop));
   }
 
-  return Owned(new ContinueStmt(ContinueLoc));
+  return Owned(new (Context) ContinueStmt(ContinueLoc));
 }
 
 Action::OwningStmtResult
@@ -713,7 +716,7 @@
     return StmtError(Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
   }
 
-  return Owned(new BreakStmt(BreakLoc));
+  return Owned(new (Context) BreakStmt(BreakLoc));
 }
 
 /// ActOnBlockReturnStmt - Utility routine to figure out block's return type.
@@ -740,10 +743,10 @@
   if (CurBlock->ReturnType->isVoidType()) {
     if (RetValExp) {
       Diag(ReturnLoc, diag::err_return_block_has_expr);
-      delete RetValExp;
+      RetValExp->Destroy(Context);
       RetValExp = 0;
     }
-    return Owned(new ReturnStmt(ReturnLoc, RetValExp));
+    return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
   }
 
   if (!RetValExp)
@@ -766,7 +769,7 @@
     if (RetValExp) CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
   }
 
-  return Owned(new ReturnStmt(ReturnLoc, RetValExp));
+  return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
 }
 
 Action::OwningStmtResult
@@ -796,7 +799,7 @@
           << RetValExp->getSourceRange();
       }
     }
-    return Owned(new ReturnStmt(ReturnLoc, RetValExp));
+    return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
   }
 
   if (!RetValExp) {
@@ -808,7 +811,7 @@
       Diag(ReturnLoc, DiagID) << FD->getIdentifier() << 0/*fn*/;
     else
       Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1/*meth*/;
-    return Owned(new ReturnStmt(ReturnLoc, (Expr*)0));
+    return Owned(new (Context) ReturnStmt(ReturnLoc, (Expr*)0));
   }
 
   if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
@@ -828,7 +831,7 @@
     if (RetValExp) CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
   }
 
-  return Owned(new ReturnStmt(ReturnLoc, RetValExp));
+  return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp));
 }
 
 Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
@@ -945,9 +948,10 @@
   exprs.release();
   asmString.release();
   clobbers.release();
-  return Owned(new AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs,
-                           Names, Constraints, Exprs, AsmString, NumClobbers,
-                           Clobbers, RParenLoc));
+  return Owned(new (Context) AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
+                                     NumInputs, Names, Constraints, Exprs,
+                                     AsmString, NumClobbers,
+                                     Clobbers, RParenLoc));
 }
 
 Action::OwningStmtResult
@@ -955,7 +959,7 @@
                            SourceLocation RParen, StmtArg Parm,
                            StmtArg Body, StmtArg catchList) {
   Stmt *CatchList = static_cast<Stmt*>(catchList.release());
-  ObjCAtCatchStmt *CS = new ObjCAtCatchStmt(AtLoc, RParen,
+  ObjCAtCatchStmt *CS = new (Context) ObjCAtCatchStmt(AtLoc, RParen,
     static_cast<Stmt*>(Parm.release()), static_cast<Stmt*>(Body.release()),
     CatchList);
   return Owned(CatchList ? CatchList : CS);
@@ -963,27 +967,29 @@
 
 Action::OwningStmtResult
 Sema::ActOnObjCAtFinallyStmt(SourceLocation AtLoc, StmtArg Body) {
-  return Owned(new ObjCAtFinallyStmt(AtLoc,
-                                     static_cast<Stmt*>(Body.release())));
+  return Owned(new (Context) ObjCAtFinallyStmt(AtLoc,
+                                           static_cast<Stmt*>(Body.release())));
 }
 
 Action::OwningStmtResult
 Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc,
                          StmtArg Try, StmtArg Catch, StmtArg Finally) {
-  return Owned(new ObjCAtTryStmt(AtLoc, static_cast<Stmt*>(Try.release()),
+  return Owned(new (Context) ObjCAtTryStmt(AtLoc,
+                                        static_cast<Stmt*>(Try.release()),
                                         static_cast<Stmt*>(Catch.release()),
                                         static_cast<Stmt*>(Finally.release())));
 }
 
 Action::OwningStmtResult
 Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg Throw) {
-  return Owned(new ObjCAtThrowStmt(AtLoc, static_cast<Expr*>(Throw.release())));
+  return Owned(new (Context) ObjCAtThrowStmt(AtLoc,
+                                          static_cast<Expr*>(Throw.release())));
 }
 
 Action::OwningStmtResult
 Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr,
                                   StmtArg SynchBody) {
-  return Owned(new ObjCAtSynchronizedStmt(AtLoc,
+  return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc,
                      static_cast<Stmt*>(SynchExpr.release()),
                      static_cast<Stmt*>(SynchBody.release())));
 }
@@ -994,8 +1000,9 @@
 Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, DeclTy *ExDecl,
                          StmtArg HandlerBlock) {
   // There's nothing to test that ActOnExceptionDecl didn't already test.
-  return Owned(new CXXCatchStmt(CatchLoc, static_cast<VarDecl*>(ExDecl),
-                                static_cast<Stmt*>(HandlerBlock.release())));
+  return Owned(new (Context) CXXCatchStmt(CatchLoc,
+                                  static_cast<VarDecl*>(ExDecl),
+                                  static_cast<Stmt*>(HandlerBlock.release())));
 }
 
 /// ActOnCXXTryBlock - Takes a try compound-statement and a number of
@@ -1022,6 +1029,7 @@
   // and warns.
 
   RawHandlers.release();
-  return Owned(new CXXTryStmt(TryLoc, static_cast<Stmt*>(TryBlock.release()),
-                              Handlers, NumHandlers));
+  return Owned(new (Context) CXXTryStmt(TryLoc,
+                                        static_cast<Stmt*>(TryBlock.release()),
+                                        Handlers, NumHandlers));
 }

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=63997&r1=63996&r2=63997&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Feb  6 19:47:29 2009
@@ -424,7 +424,10 @@
         Diag(ArraySize->getLocStart(), diag::err_array_size_non_int)
           << ArraySize->getType() << ArraySize->getSourceRange();
         D.setInvalidType(true);
-        delete ArraySize;
+        
+        Context.Deallocate(ArraySize);
+        ArraySize->~Expr();
+
         ATI.NumElts = ArraySize = 0;
       }
       llvm::APSInt ConstVal(32);





More information about the cfe-commits mailing list