[cfe-commits] r79199 - in /cfe/trunk/lib/CodeGen: CodeGenModule.cpp CodeGenModule.h

Fariborz Jahanian fjahanian at apple.com
Sun Aug 16 12:36:18 PDT 2009


Author: fjahanian
Date: Sun Aug 16 14:36:17 2009
New Revision: 79199

URL: http://llvm.org/viewvc/llvm-project?rev=79199&view=rev
Log:
Patch toward synthesizing non-trivial destructors. WIP

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Aug 16 14:36:17 2009
@@ -657,6 +657,8 @@
       else if (!ClassDecl->hasUserDeclaredConstructor())
         DeferredDeclsToEmit.push_back(D);
     }
+    else if (isa<CXXDestructorDecl>(FD)) 
+       DeferredDestructorToEmit(D);
     else if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
            if (MD->isCopyAssignment())
              DeferredCopyAssignmentToEmit(D);
@@ -766,6 +768,42 @@
   DeferredDeclsToEmit.push_back(CopyAssignDecl);  
 }
 
+void CodeGenModule::DeferredDestructorToEmit(GlobalDecl DtorDecl) {
+  const CXXDestructorDecl *DD = cast<CXXDestructorDecl>(DtorDecl.getDecl());
+  const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(DD->getDeclContext());
+  if (ClassDecl->hasTrivialDestructor() ||
+      ClassDecl->hasUserDeclaredDestructor())
+    return;
+
+  for (CXXRecordDecl::base_class_const_iterator Base = ClassDecl->bases_begin();
+       Base != ClassDecl->bases_end(); ++Base) {
+    CXXRecordDecl *BaseClassDecl
+      = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
+    if (const CXXDestructorDecl *BaseDtor = 
+          BaseClassDecl->getDestructor(Context))
+      GetAddrOfCXXDestructor(BaseDtor, Dtor_Complete);
+  }
+ 
+  for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
+       FieldEnd = ClassDecl->field_end();
+       Field != FieldEnd; ++Field) {
+    QualType FieldType = Context.getCanonicalType((*Field)->getType());
+    if (const ArrayType *Array = Context.getAsArrayType(FieldType))
+      FieldType = Array->getElementType();
+    if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) {
+      if ((*Field)->isAnonymousStructOrUnion())
+        continue;
+      CXXRecordDecl *FieldClassDecl
+        = cast<CXXRecordDecl>(FieldClassType->getDecl());
+      if (const CXXDestructorDecl *FieldDtor = 
+            FieldClassDecl->getDestructor(Context))
+        GetAddrOfCXXDestructor(FieldDtor, Dtor_Complete);
+    }
+  }
+  DeferredDeclsToEmit.push_back(DtorDecl);
+}
+
+
 /// GetAddrOfFunction - Return the address of the given function.  If Ty is
 /// non-null, then this function will use the specified type if it has to
 /// create it (this occurs when we see a definition of the function).

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=79199&r1=79198&r2=79199&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Sun Aug 16 14:36:17 2009
@@ -399,6 +399,7 @@
                                         const VarDecl *D);
   void DeferredCopyConstructorToEmit(GlobalDecl D);
   void DeferredCopyAssignmentToEmit(GlobalDecl D);
+  void DeferredDestructorToEmit(GlobalDecl D);
   
   /// SetCommonAttributes - Set attributes which are common to any
   /// form of a global definition (alias, Objective-C method,





More information about the cfe-commits mailing list