aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/Expr.cpp20
-rw-r--r--lib/AST/ExprCXX.cpp4
-rw-r--r--lib/AST/Stmt.cpp2
-rw-r--r--lib/AST/StmtSerialization.cpp25
-rw-r--r--lib/Sema/Sema.cpp2
-rw-r--r--lib/Sema/Sema.h21
-rw-r--r--lib/Sema/SemaChecking.cpp7
-rw-r--r--lib/Sema/SemaDecl.cpp28
-rw-r--r--lib/Sema/SemaDeclCXX.cpp4
-rw-r--r--lib/Sema/SemaExpr.cpp15
-rw-r--r--lib/Sema/SemaExprCXX.cpp34
-rw-r--r--lib/Sema/SemaExprObjC.cpp41
-rw-r--r--lib/Sema/SemaNamedCast.cpp16
-rw-r--r--lib/Sema/SemaOverload.cpp36
-rw-r--r--lib/Sema/SemaStmt.cpp84
-rw-r--r--lib/Sema/SemaType.cpp5
16 files changed, 191 insertions, 153 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 89fdbe31f3..d686167cd0 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -54,8 +54,8 @@ StringLiteral::StringLiteral(ASTContext& C, const char *strData,
}
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 @@ const char *UnaryOperator::getOpcodeStr(Opcode Op) {
// 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 @@ CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
/// 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 @@ void CallExpr::setNumArgs(unsigned NumArgs) {
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 @@ void SizeOfAlignOfExpr::Destroy(ASTContext& C) {
// 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);
}
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index b328c1ef3d..801a0f22e2 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -20,10 +20,10 @@ void CXXConditionDeclExpr::Destroy(ASTContext& C) {
// 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
//===----------------------------------------------------------------------===//
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 541bb0401c..49c8c80509 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -219,7 +219,7 @@ Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
// 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]; }
diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp
index 8d6636d6a6..92713cc633 100644
--- a/lib/AST/StmtSerialization.cpp
+++ b/lib/AST/StmtSerialization.cpp
@@ -483,7 +483,8 @@ void CompoundLiteralExpr::EmitImpl(Serializer& S) const {
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 @@ CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D, ASTContext
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 @@ CompoundStmt* CompoundStmt::CreateImpl(Deserializer& D, ASTContext& C) {
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 @@ ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C) {
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 {
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 028c9ebf4f..8667ee28e2 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -183,7 +183,7 @@ void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, bool isLvalue) {
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) {
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 4878403333..88d7a0f6f4 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1970,7 +1970,7 @@ struct BlockSemaInfo {
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 @@ struct BlockSemaInfo {
/// 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
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 92cad1029b..e52c730442 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -306,9 +306,10 @@ Action::OwningExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
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.
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index bf16e1aeee..cdb6930536 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2260,7 +2260,7 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit) {
// 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 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) {
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 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) {
// 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 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
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 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
// 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 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
// 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 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name,
!Val.isPowerOf2() ||
Val.getZExtValue() > 16) {
Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
- delete Alignment;
+ Alignment->Destroy(Context);
return; // Ignore
}
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 35050e517b..c4c526eedb 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -107,7 +107,7 @@ void
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 @@ void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc,
// 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;
}
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 201a0f99e3..8ce8bfdd8b 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -454,8 +454,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
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 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
<< 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 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
<< 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 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc,
// 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 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
// 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 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
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 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body,
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();
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 2a7c9a85f0..748eddc5f7 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -70,8 +70,8 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc,
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 @@ Action::ExprResult
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 @@ Action::ExprResult Sema::ActOnCXXThis(SourceLocation ThisLoc) {
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 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
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 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
if (!Constructor)
return true;
- return new CXXTemporaryObjectExpr(Constructor, Ty, TyBeginLoc,
+ return new (Context) CXXTemporaryObjectExpr(Constructor, Ty, TyBeginLoc,
Exprs, NumExprs, RParenLoc);
}
@@ -178,7 +178,7 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
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 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
// 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 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, bool UseGlobal,
// 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 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
// 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 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
// 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 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc,
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 @@ Sema::OwningExprResult Sema::ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
// 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));
}
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 003e121f37..32ff7ff163 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -38,7 +38,7 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
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 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
} 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 @@ Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
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 @@ Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
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 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,
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 @@ Sema::ExprResult Sema::ActOnClassMessage(
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 @@ Sema::ExprResult Sema::ActOnClassMessage(
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 @@ Sema::ExprResult Sema::ActOnClassMessage(
// 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 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
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 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
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 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
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 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
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);
}
//===----------------------------------------------------------------------===//
diff --git a/lib/Sema/SemaNamedCast.cpp b/lib/Sema/SemaNamedCast.cpp
index e2137b3001..c5bee98a37 100644
--- a/lib/Sema/SemaNamedCast.cpp
+++ b/lib/Sema/SemaNamedCast.cpp
@@ -76,26 +76,26 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
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;
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index cb659002b3..69bbf0e05a 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -3600,9 +3600,9 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
// 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 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
}
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 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
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 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
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 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
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 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Base, 0, 0, CandidateSet,
/*SuppressUserConversions=*/false);
- llvm::OwningPtr<Expr&