[cfe-commits] r79196 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/CodeGen/CGExpr.cpp

Anders Carlsson andersca at mac.com
Sun Aug 16 10:50:26 PDT 2009


Author: andersca
Date: Sun Aug 16 12:50:25 2009
New Revision: 79196

URL: http://llvm.org/viewvc/llvm-project?rev=79196&view=rev
Log:
Destroy bound temporaries.

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=79196&r1=79195&r2=79196&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sun Aug 16 12:50:25 2009
@@ -486,7 +486,6 @@
   
   Stmt **Args;
   unsigned NumArgs;
-
   
 protected:
   CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=79196&r1=79195&r2=79196&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sun Aug 16 12:50:25 2009
@@ -87,8 +87,24 @@
       return RValue::get(LV.getAddress());
     Val = EmitLoadOfLValue(LV, E->getType());
   } else {
+    // FIXME: Initializers don't work with casts yet. For example
+    // const A& a = B();
+    // if B inherits from A.
     Val = EmitAnyExprToTemp(E, /*IsAggLocVolatile=*/false,
                             IsInitializer);
+    
+    // We might have to destroy the temporary variable.
+    if (const RecordType *RT = E->getType()->getAs<RecordType>()) {
+      if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+        if (!ClassDecl->hasTrivialDestructor()) {
+          const CXXDestructorDecl *Dtor = 
+            ClassDecl->getDestructor(getContext());
+          
+          CleanupScope scope(*this);
+          EmitCXXDestructorCall(Dtor, Dtor_Complete, Val.getAggregateAddr());
+        }
+      }
+    }
   }
 
   if (Val.isAggregate()) {





More information about the cfe-commits mailing list