[cfe-commits] r131068 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/abstract-class-ctors-dtors.cpp

Anders Carlsson andersca at mac.com
Sun May 8 10:25:05 PDT 2011


Author: andersca
Date: Sun May  8 12:25:05 2011
New Revision: 131068

URL: http://llvm.org/viewvc/llvm-project?rev=131068&view=rev
Log:
Don't emit complete constructors for abstract classes. Also, don't emit
complete destructors for abstract classes unless the destructor is virtual
and thus needs to be in the vtable.

Added:
    cfe/trunk/test/CodeGenCXX/abstract-class-ctors-dtors.cpp
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=131068&r1=131067&r2=131068&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sun May  8 12:25:05 2011
@@ -187,7 +187,10 @@
 void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
   // The constructor used for constructing this as a complete class;
   // constucts the virtual bases, then calls the base constructor.
-  EmitGlobal(GlobalDecl(D, Ctor_Complete));
+  if (!D->getParent()->isAbstract()) {
+    // We don't need to emit the complete ctor if the class is abstract.
+    EmitGlobal(GlobalDecl(D, Ctor_Complete));
+  }
 
   // The constructor used for constructing this as a base class;
   // ignores virtual bases.
@@ -244,7 +247,11 @@
 
   // 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));
+  if (!D->getParent()->isAbstract() || D->isVirtual()) {
+    // We don't need to emit the complete ctor if the class is abstract,
+    // unless the destructor is virtual and needs to be in the vtable.
+    EmitGlobal(GlobalDecl(D, Dtor_Complete));
+  }
 
   // The destructor used for destructing this as a base class; ignores
   // virtual bases.

Added: cfe/trunk/test/CodeGenCXX/abstract-class-ctors-dtors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/abstract-class-ctors-dtors.cpp?rev=131068&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/abstract-class-ctors-dtors.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/abstract-class-ctors-dtors.cpp Sun May  8 12:25:05 2011
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+
+// Check that we dont emit the complete constructor/destructor for this class.
+struct A {
+  virtual void f() = 0;
+  A();
+  ~A();
+};
+
+// CHECK-NOT: define void @_ZN1AC1Ev
+// CHECK: define void @_ZN1AC2Ev
+// CHECK-NOT: define void @_ZN1AD1Ev
+// CHECK: define void @_ZN1AD2Ev
+A::A() { }
+
+A::~A() { }





More information about the cfe-commits mailing list