]> granicus.if.org Git - clang/commitdiff
ShouldDestroyTemporaries? I don't think so.
authorAnders Carlsson <andersca@mac.com>
Tue, 15 Dec 2009 20:51:39 +0000 (20:51 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 15 Dec 2009 20:51:39 +0000 (20:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91450 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprCXX.h
lib/AST/ExprCXX.cpp
lib/AST/StmtProfile.cpp
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGTemporaries.cpp
lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaStmt.cpp
lib/Sema/TreeTransform.h

index 00ea202abde73c19a793513c4e68c821d77ec325..8f424474a4c7663f6901317a422d317c214595aa 100644 (file)
@@ -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<CXXExprWithTemporaries*>(this)->getTemporary(i);
   }
 
-  bool shouldDestroyTemporaries() const { return ShouldDestroyTemps; }
-
-  void removeLastTemporary() { NumTemps--; }
-
   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
   void setSubExpr(Expr *E) { SubExpr = E; }
index a9f96adae137b093a0f545d0c6fafd91ba57633f..eecdba1ecaa4d7e729909545460b021fe7caf275 100644 (file)
@@ -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) {
index e2d772b7dd12a1e16335d819be4d6e50d80b1362..b74e1ef0bab466aa678c3b63d3267df1212827a0 100644 (file)
@@ -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<CXXDestructorDecl *>(S->getTemporary(I)->getDestructor()));
index e6bbfa8063fa0218d76bd5932fed4345a04e08ac..8e1413386af499885a8f05133bef09921db6e0ac 100644 (file)
@@ -99,11 +99,10 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
   unsigned OldNumLiveTemporaries = 0;
   
   if (const CXXExprWithTemporaries *TE = dyn_cast<CXXExprWithTemporaries>(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();
   }
index 5cfc7efade42b6dd1e3d3447b0091144804c44fd..884c21230adaa22a44db72e01ad427cd81c5dcaf 100644 (file)
@@ -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;
index ada8aa157a406ab4f2420b208334ba78d6534048..32a57269d6b596e3e3b5771d3da0e670c22d0a5a 100644 (file)
@@ -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);
 
index 14d2377784d5d34adde2dc1e6d44942e436e0896..6c5c2595aef5680645344687701f781daac56f18 100644 (file)
@@ -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);
 
index 831d58dad5f978d7e87306beb76a739bd801a83a..80d67efae9b1b3e066a6a6f781673f451380a642 100644 (file)
@@ -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<Expr>();
   MarkDeclarationReferenced(VD->getLocation(), Constructor);
-  Temp = MaybeCreateCXXExprWithTemporaries(Temp, /*DestroyTemps=*/true);
+  Temp = MaybeCreateCXXExprWithTemporaries(Temp);
   VD->setInit(Context, Temp);
 
   return false;
index 6d991b6a7c6bdc95e54c81125a8cb7c70c44493c..d119350a6f5389b1089fd9a7f42fc506168c8b1c 100644 (file)
@@ -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<Expr>();
   if (FullExpr)
-    FullExpr = MaybeCreateCXXExprWithTemporaries(FullExpr,
-                                                 /*ShouldDestroyTemps=*/true);
-
+    FullExpr = MaybeCreateCXXExprWithTemporaries(FullExpr);
 
   return Owned(FullExpr);
 }
index de67a5f1a75fa74051b45b42d0644c6202b1ced9..acf3e3aad7c619a076386e3c2e75251fafd412a0 100644 (file)
@@ -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));
 }
 
index fd19987344371e89179d2c1e36d41cedb5331bd5..cc5722297fc42d11ecab42bdac7b9a4f79ecd25e 100644 (file)
@@ -4755,8 +4755,7 @@ TreeTransform<Derived>::TransformCXXExprWithTemporaries(
     return SemaRef.ExprError();
 
   return SemaRef.Owned(
-           SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
-                                               E->shouldDestroyTemporaries()));
+           SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>()));
 }
 
 template<typename Derived>