From d04ed416be7c55bddddab1fa3fd38a0113a6b3da Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 10 May 2010 20:06:30 +0000 Subject: [PATCH] Convert CXXTempory[] in CXXExprWithTemporaries to be allocated using ASTContext's allocator. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103421 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprCXX.h | 4 ++-- lib/AST/ExprCXX.cpp | 19 +++++++++---------- lib/Frontend/PCHReaderStmt.cpp | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 5dd29122ac..34bfc56f23 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1696,7 +1696,7 @@ class CXXExprWithTemporaries : public Expr { CXXTemporary **Temps; unsigned NumTemps; - CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps, + CXXExprWithTemporaries(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps, unsigned NumTemps); ~CXXExprWithTemporaries(); @@ -1713,7 +1713,7 @@ public: unsigned NumTemps); unsigned getNumTemporaries() const { return NumTemps; } - void setNumTemporaries(unsigned N); + void setNumTemporaries(ASTContext &C, unsigned N); CXXTemporary *getTemporary(unsigned i) { assert(i < NumTemps && "Index out of range"); diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 709f12b1b4..1e8d61a216 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -527,24 +527,24 @@ void CXXConstructExpr::DoDestroy(ASTContext &C) { C.Deallocate(this); } -CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr, +CXXExprWithTemporaries::CXXExprWithTemporaries(ASTContext &C, + Expr *subexpr, CXXTemporary **temps, unsigned numtemps) : Expr(CXXExprWithTemporariesClass, subexpr->getType(), subexpr->isTypeDependent(), subexpr->isValueDependent()), SubExpr(subexpr), Temps(0), NumTemps(0) { if (numtemps) { - setNumTemporaries(numtemps); + setNumTemporaries(C, numtemps); for (unsigned i = 0; i != numtemps; ++i) Temps[i] = temps[i]; } } -void CXXExprWithTemporaries::setNumTemporaries(unsigned N) { +void CXXExprWithTemporaries::setNumTemporaries(ASTContext &C, unsigned N) { assert(Temps == 0 && "Cannot resize with this"); NumTemps = N; - // FIXME: This is a memory leak in disable free mode. - Temps = new CXXTemporary*[NumTemps]; + Temps = new (C) CXXTemporary*[NumTemps]; } @@ -552,19 +552,18 @@ CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps, unsigned NumTemps) { - return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps); + return new (C) CXXExprWithTemporaries(C, SubExpr, Temps, NumTemps); } void CXXExprWithTemporaries::DoDestroy(ASTContext &C) { DestroyChildren(C); + if (Temps) + C.Deallocate(Temps); this->~CXXExprWithTemporaries(); C.Deallocate(this); } -CXXExprWithTemporaries::~CXXExprWithTemporaries() { - // FIXME: This is a memory leak in disable free mode. - delete[] Temps; -} +CXXExprWithTemporaries::~CXXExprWithTemporaries() {} // CXXBindTemporaryExpr Stmt::child_iterator CXXBindTemporaryExpr::child_begin() { diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index 5442013e1b..b3aafce444 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -1085,7 +1085,7 @@ unsigned PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) { VisitExpr(E); unsigned NumTemps = Record[Idx++]; if (NumTemps) { - E->setNumTemporaries(NumTemps); + E->setNumTemporaries(*Reader.getContext(), NumTemps); for (unsigned i = 0; i != NumTemps; ++i) E->setTemporary(i, Reader.ReadCXXTemporary(Record, Idx)); } -- 2.40.0