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!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63997 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 2a7c9a8..748eddc 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -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));
 }