From: Anders Carlsson Date: Tue, 15 Dec 2009 20:51:39 +0000 (+0000) Subject: ShouldDestroyTemporaries? I don't think so. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ece491d8f62ce67f047491a6703fac0d3bd4ff4;p=clang ShouldDestroyTemporaries? I don't think so. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91450 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 00ea202abd..8f424474a4 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1264,10 +1264,8 @@ class CXXExprWithTemporaries : public Expr { CXXTemporary **Temps; unsigned NumTemps; - bool ShouldDestroyTemps; - CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps, - unsigned NumTemps, bool ShouldDestroyTemps); + unsigned NumTemps); ~CXXExprWithTemporaries(); protected: @@ -1275,8 +1273,8 @@ protected: public: static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr, - CXXTemporary **Temps, unsigned NumTemps, - bool ShouldDestroyTemporaries); + CXXTemporary **Temps, + unsigned NumTemps); unsigned getNumTemporaries() const { return NumTemps; } CXXTemporary *getTemporary(unsigned i) { @@ -1284,14 +1282,9 @@ public: return Temps[i]; } const CXXTemporary *getTemporary(unsigned i) const { - assert(i < NumTemps && "Index out of range"); - return Temps[i]; + return const_cast(this)->getTemporary(i); } - bool shouldDestroyTemporaries() const { return ShouldDestroyTemps; } - - void removeLastTemporary() { NumTemps--; } - Expr *getSubExpr() { return cast(SubExpr); } const Expr *getSubExpr() const { return cast(SubExpr); } void setSubExpr(Expr *E) { SubExpr = E; } diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index a9f96adae1..eecdba1eca 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -420,12 +420,10 @@ void CXXConstructExpr::DoDestroy(ASTContext &C) { CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr, CXXTemporary **temps, - unsigned numtemps, - bool shoulddestroytemps) + unsigned numtemps) : Expr(CXXExprWithTemporariesClass, subexpr->getType(), subexpr->isTypeDependent(), subexpr->isValueDependent()), - SubExpr(subexpr), Temps(0), NumTemps(numtemps), - ShouldDestroyTemps(shoulddestroytemps) { + SubExpr(subexpr), Temps(0), NumTemps(numtemps) { if (NumTemps > 0) { Temps = new CXXTemporary*[NumTemps]; for (unsigned i = 0; i < NumTemps; ++i) @@ -436,10 +434,8 @@ CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr, CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps, - unsigned NumTemps, - bool ShouldDestroyTemps){ - return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps, - ShouldDestroyTemps); + unsigned NumTemps) { + return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps); } void CXXExprWithTemporaries::DoDestroy(ASTContext &C) { diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index e2d772b7dd..b74e1ef0ba 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -540,7 +540,6 @@ StmtProfiler::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *S) { void StmtProfiler::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *S) { VisitExpr(S); - ID.AddBoolean(S->shouldDestroyTemporaries()); for (unsigned I = 0, N = S->getNumTemporaries(); I != N; ++I) VisitDecl( const_cast(S->getTemporary(I)->getDestructor())); diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index e6bbfa8063..8e1413386a 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -99,11 +99,10 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E, unsigned OldNumLiveTemporaries = 0; if (const CXXExprWithTemporaries *TE = dyn_cast(E)) { - ShouldDestroyTemporaries = TE->shouldDestroyTemporaries(); - + ShouldDestroyTemporaries = true; + // Keep track of the current cleanup stack depth. - if (ShouldDestroyTemporaries) - OldNumLiveTemporaries = LiveTemporaries.size(); + OldNumLiveTemporaries = LiveTemporaries.size(); E = TE->getSubExpr(); } diff --git a/lib/CodeGen/CGTemporaries.cpp b/lib/CodeGen/CGTemporaries.cpp index 5cfc7efade..884c21230a 100644 --- a/lib/CodeGen/CGTemporaries.cpp +++ b/lib/CodeGen/CGTemporaries.cpp @@ -92,12 +92,6 @@ CodeGenFunction::EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, llvm::Value *AggLoc, bool IsAggLocVolatile, bool IsInitializer) { - // If we shouldn't destroy the temporaries, just emit the - // child expression. - if (!E->shouldDestroyTemporaries()) - return EmitAnyExpr(E->getSubExpr(), AggLoc, IsAggLocVolatile, - /*IgnoreResult=*/false, IsInitializer); - // Keep track of the current cleanup stack depth. size_t CleanupStackDepth = CleanupEntries.size(); (void) CleanupStackDepth; @@ -119,11 +113,6 @@ CodeGenFunction::EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, LValue CodeGenFunction::EmitCXXExprWithTemporariesLValue( const CXXExprWithTemporaries *E) { - // If we shouldn't destroy the temporaries, just emit the - // child expression. - if (!E->shouldDestroyTemporaries()) - return EmitLValue(E->getSubExpr()); - // Keep track of the current cleanup stack depth. size_t CleanupStackDepth = CleanupEntries.size(); (void) CleanupStackDepth; diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index ada8aa157a..32a57269d6 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -2003,8 +2003,7 @@ public: /// MaybeCreateCXXExprWithTemporaries - If the list of temporaries is /// non-empty, will create a new CXXExprWithTemporaries expression. /// Otherwise, just returs the passed in expression. - Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr, - bool ShouldDestroyTemporaries); + Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr); virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 14d2377784..6c5c2595ae 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3622,8 +3622,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { Init->setType(DclT); } - Init = MaybeCreateCXXExprWithTemporaries(Init, - /*ShouldDestroyTemporaries=*/true); + Init = MaybeCreateCXXExprWithTemporaries(Init); // Attach the initializer to the decl. VDecl->setInit(Context, Init); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 831d58dad5..80d67efae9 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -129,7 +129,7 @@ Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, Param->getDeclName(), /*DirectInit=*/false)) return true; - Arg = MaybeCreateCXXExprWithTemporaries(Arg, /*DestroyTemps=*/false); + Arg = MaybeCreateCXXExprWithTemporaries(Arg); // Okay: add the default argument to the parameter Param->setDefaultArg(Arg); @@ -3806,7 +3806,7 @@ bool Sema::InitializeVarWithConstructor(VarDecl *VD, Expr *Temp = TempResult.takeAs(); MarkDeclarationReferenced(VD->getLocation(), Constructor); - Temp = MaybeCreateCXXExprWithTemporaries(Temp, /*DestroyTemps=*/true); + Temp = MaybeCreateCXXExprWithTemporaries(Temp); VD->setInit(Context, Temp); return false; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 6d991b6a7c..d119350a6f 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2089,8 +2089,7 @@ Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) { return Owned(CXXBindTemporaryExpr::Create(Context, Temp, E)); } -Expr *Sema::MaybeCreateCXXExprWithTemporaries(Expr *SubExpr, - bool ShouldDestroyTemps) { +Expr *Sema::MaybeCreateCXXExprWithTemporaries(Expr *SubExpr) { assert(SubExpr && "sub expression can't be null!"); unsigned FirstTemporary = ExprEvalContexts.back().NumTemporaries; @@ -2100,8 +2099,7 @@ Expr *Sema::MaybeCreateCXXExprWithTemporaries(Expr *SubExpr, Expr *E = CXXExprWithTemporaries::Create(Context, SubExpr, &ExprTemporaries[FirstTemporary], - ExprTemporaries.size() - FirstTemporary, - ShouldDestroyTemps); + ExprTemporaries.size() - FirstTemporary); ExprTemporaries.erase(ExprTemporaries.begin() + FirstTemporary, ExprTemporaries.end()); @@ -2243,9 +2241,7 @@ Sema::OwningExprResult Sema::BuildCXXCastArgument(SourceLocation CastLoc, Sema::OwningExprResult Sema::ActOnFinishFullExpr(ExprArg Arg) { Expr *FullExpr = Arg.takeAs(); if (FullExpr) - FullExpr = MaybeCreateCXXExprWithTemporaries(FullExpr, - /*ShouldDestroyTemps=*/true); - + FullExpr = MaybeCreateCXXExprWithTemporaries(FullExpr); return Owned(FullExpr); } diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index de67a5f1a7..acf3e3aad7 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1053,7 +1053,7 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { << RetValExp->getSourceRange(); } - RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp, true); + RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp); } return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp)); } @@ -1098,7 +1098,7 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { // FIXME: Leaks RetValExp on error. if (PerformCopyInitialization(RetValExp, FnRetType, "returning", Elidable)){ // We should still clean up our temporaries, even when we're failing! - RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp, true); + RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp); return StmtError(); } @@ -1106,7 +1106,7 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { } if (RetValExp) - RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp, true); + RetValExp = MaybeCreateCXXExprWithTemporaries(RetValExp); return Owned(new (Context) ReturnStmt(ReturnLoc, RetValExp)); } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index fd19987344..cc5722297f 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -4755,8 +4755,7 @@ TreeTransform::TransformCXXExprWithTemporaries( return SemaRef.ExprError(); return SemaRef.Owned( - SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs(), - E->shouldDestroyTemporaries())); + SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs())); } template