[PATCH] [ms-cxxabi] Emit linkonce complete dtors in TUs that need them

John McCall rjmccall at apple.com
Fri Jul 19 20:12:58 PDT 2013


On Jul 19, 2013, at 12:29 PM, Reid Kleckner <rnk at google.com> wrote:
>    - Add a big comment block that should have been there and minor stuff.

 void CodeGenModule::EmitCXXDestructors(const CXXDestructorDecl *D) {
-  // The destructor in a virtual table is always a 'deleting'
-  // destructor, which calls the complete destructor and then uses the
-  // appropriate operator delete.
-  if (D->isVirtual())
-    EmitGlobal(GlobalDecl(D, Dtor_Deleting));
-
-  // The destructor used for destructing this as a most-derived class;
-  // call the base destructor and then destructs any virtual bases.
-  EmitGlobal(GlobalDecl(D, Dtor_Complete));

Just delegate this entire method to the ABI.

+  /// Returns true if the given destructor type should be emitted as a linkonce
+  /// delegating thunk, regardless of whether the dtor is defined in this TU or
+  /// not.
+  virtual bool useThunkForDtorVariant(CXXDtorType DT) const = 0;

Go ahead and make this take the destructor decl as well.

-bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) {
+bool CodeGenModule::MayDeferGeneration(const ValueDecl *D) {
   // Never defer when EmitAllDecls is specified.
   if (LangOpts.EmitAllDecls)
     return false;
 
-  return !getContext().DeclMustBeEmitted(Global);
+  return !getContext().DeclMustBeEmitted(D);
 }

This rename is now spurious.

+  if (getLangOpts().CPlusPlus && D && isa<CXXDestructorDecl>(D) &&
+      getCXXABI().useThunkForDtorVariant(GD.getDtorType()))
+    DeferredDeclsToEmit.push_back(GD);

Don’t bother with the language check.

+  // All MSVC dtors other than the base dtor are linkonce_odr and delegate to
+  // each other bottoming out with the base dtor.  Therefore we emit non-base
+  // dtors on usage, even if there is no dtor definition in the TU.

This comment doesn’t need to be MSVC-specific.  Just say “if the C++
ABI says this variant is a thunk, then we need to emit its definition on use.”

 CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName,
                                        llvm::Type *Ty,
-                                       GlobalDecl D, bool ForVTable,
+                                       GlobalDecl GD, bool ForVTable,
                                        llvm::AttributeSet ExtraAttrs) {

I agree with this rename, but please do it as a separate patch.

Otherwise, this looks great, thanks!

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130719/dff25c96/attachment.html>


More information about the cfe-commits mailing list