[cfe-commits] r90158 - /cfe/trunk/lib/CodeGen/CGCXX.cpp

Fariborz Jahanian fjahanian at apple.com
Mon Nov 30 14:07:18 PST 2009


Author: fjahanian
Date: Mon Nov 30 16:07:18 2009
New Revision: 90158

URL: http://llvm.org/viewvc/llvm-project?rev=90158&view=rev
Log:
More support for virtual destructor calls.
Fixes pr5619

Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Nov 30 16:07:18 2009
@@ -603,16 +603,7 @@
   Counter = Builder.CreateLoad(IndexPtr);
   Counter = Builder.CreateSub(Counter, One);
   llvm::Value *Address = Builder.CreateInBoundsGEP(This, Counter, "arrayidx");
-  if (D->isVirtual()) {
-    const llvm::Type *Ty =
-      CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(D),
-                                     /*isVariadic=*/false);
-    
-    llvm::Value *Callee = BuildVirtualCall(D, Dtor_Deleting, Address, Ty);
-    EmitCXXMemberCall(D, Callee, Address, 0, 0);
-  }
-  else
-    EmitCXXDestructorCall(D, Dtor_Complete, Address);
+  EmitCXXDestructorCall(D, Dtor_Complete, Address);
 
   EmitBlock(ContinueBlock);
 
@@ -703,6 +694,15 @@
 void CodeGenFunction::EmitCXXDestructorCall(const CXXDestructorDecl *D,
                                             CXXDtorType Type,
                                             llvm::Value *This) {
+  if (D->isVirtual()) {
+    const llvm::Type *Ty =
+      CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(D),
+                                     /*isVariadic=*/false);
+    
+    llvm::Value *Callee = BuildVirtualCall(D, Dtor_Deleting, This, Ty);
+    EmitCXXMemberCall(D, Callee, This, 0, 0);
+    return;
+  }
   llvm::Value *Callee = CGM.GetAddrOfCXXDestructor(D, Type);
 
   EmitCXXMemberCall(D, Callee, This, 0, 0);
@@ -1777,12 +1777,12 @@
     // Ignore trivial destructors.
     if (BaseClassDecl->hasTrivialDestructor())
       continue;
-
+    const CXXDestructorDecl *D = BaseClassDecl->getDestructor(getContext());
+    
     llvm::Value *V = GetAddressOfBaseClass(LoadCXXThis(),
                                            ClassDecl, BaseClassDecl, 
                                            /*NullCheckValue=*/false);
-    EmitCXXDestructorCall(BaseClassDecl->getDestructor(getContext()),
-                          Dtor_Base, V);
+    EmitCXXDestructorCall(D, Dtor_Base, V);
   }
 
   // If we're emitting a base destructor, we don't want to emit calls to the
@@ -1790,10 +1790,21 @@
   if (DtorType == Dtor_Base)
     return;
   
-  // FIXME: Handle virtual bases.
+  // Handle virtual bases.
   for (CXXRecordDecl::reverse_base_class_const_iterator I = 
        ClassDecl->vbases_rbegin(), E = ClassDecl->vbases_rend(); I != E; ++I) {
-    assert(false && "FIXME: Handle virtual bases.");
+    const CXXBaseSpecifier &Base = *I;
+    CXXRecordDecl *BaseClassDecl
+    = cast<CXXRecordDecl>(Base.getType()->getAs<RecordType>()->getDecl());
+    
+    // Ignore trivial destructors.
+    if (BaseClassDecl->hasTrivialDestructor())
+      continue;
+    const CXXDestructorDecl *D = BaseClassDecl->getDestructor(getContext());
+    llvm::Value *V = GetAddressOfBaseClass(LoadCXXThis(),
+                                           ClassDecl, BaseClassDecl, 
+                                           /*NullCheckValue=*/false);
+    EmitCXXDestructorCall(D, Dtor_Base, V);
   }
     
   // If we have a deleting destructor, emit a call to the delete operator.





More information about the cfe-commits mailing list