[cfe-commits] r97637 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/destructors.cpp

John McCall rjmccall at apple.com
Tue Mar 2 19:40:11 PST 2010


Author: rjmccall
Date: Tue Mar  2 21:40:11 2010
New Revision: 97637

URL: http://llvm.org/viewvc/llvm-project?rev=97637&view=rev
Log:
Don't emit derived-to-base destructor aliases if we don't have a definition
for the base destructor, because aliases to declarations aren't legal.

Fixes PR 6471.


Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/test/CodeGenCXX/destructors.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=97637&r1=97636&r2=97637&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Mar  2 21:40:11 2010
@@ -93,12 +93,18 @@
   if (!UniqueBase)
     return true;
 
+  /// If we don't have a definition for the destructor yet, don't
+  /// emit.  We can't emit aliases to declarations; that's just not
+  /// how aliases work.
+  const CXXDestructorDecl *BaseD = UniqueBase->getDestructor(getContext());
+  if (!BaseD->isImplicit() && !BaseD->getBody())
+    return true;
+
   // If the base is at a non-zero offset, give up.
   const ASTRecordLayout &ClassLayout = Context.getASTRecordLayout(Class);
   if (ClassLayout.getBaseClassOffset(UniqueBase) != 0)
     return true;
 
-  const CXXDestructorDecl *BaseD = UniqueBase->getDestructor(getContext());
   return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
                                   GlobalDecl(BaseD, Dtor_Base));
 }

Modified: cfe/trunk/test/CodeGenCXX/destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=97637&r1=97636&r2=97637&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/destructors.cpp Tue Mar  2 21:40:11 2010
@@ -104,6 +104,10 @@
   struct Empty { }; // trivial destructor, empty
   struct NonEmpty { int x; }; // trivial destructor, non-empty
 
+  // There must be a definition in this translation unit for the alias
+  // optimization to apply.
+  A::~A() { delete m; }
+
   struct M : A { ~M(); };
   M::~M() {} // alias tested above
 
@@ -133,3 +137,13 @@
   struct U : A, virtual B { ~U(); };
   U::~U() {} // CHECK: define void @_ZN5test11UD2Ev
 }
+
+// PR6471
+namespace test2 {
+  struct A { ~A(); char ***m; };
+  struct B : A { ~B(); };
+
+  B::~B() {}
+  // CHECK: define void @_ZN5test21BD2Ev
+  // CHECK: call void @_ZN5test21AD2Ev
+}





More information about the cfe-commits mailing list