r204786 - Fix PR19066 - 0-sized vftable in the presence of virtual inheritance

Timur Iskhodzhanov timurrrr at google.com
Wed Mar 26 01:12:55 PDT 2014


Author: timurrrr
Date: Wed Mar 26 03:12:53 2014
New Revision: 204786

URL: http://llvm.org/viewvc/llvm-project?rev=204786&view=rev
Log:
Fix PR19066 - 0-sized vftable in the presence of virtual inheritance

Reviewed at http://llvm-reviews.chandlerc.com/D3181

Modified:
    cfe/trunk/lib/AST/VTableBuilder.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp

Modified: cfe/trunk/lib/AST/VTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=204786&r1=204785&r2=204786&view=diff
==============================================================================
--- cfe/trunk/lib/AST/VTableBuilder.cpp (original)
+++ cfe/trunk/lib/AST/VTableBuilder.cpp Wed Mar 26 03:12:53 2014
@@ -2531,6 +2531,7 @@ private:
     BasesSetVectorTy VisitedBases;
     AddMethods(BaseSubobject(MostDerivedClass, CharUnits::Zero()), 0, 0,
                VisitedBases);
+    assert(Components.size() && "vftable can't be empty");
 
     assert(MethodVFTableLocations.empty());
     for (MethodInfoMapTy::const_iterator I = MethodInfoMap.begin(),
@@ -2793,6 +2794,14 @@ bool VFTableBuilder::NeedsReturnAdjustin
   return false;
 }
 
+static bool isDirectVBase(const CXXRecordDecl *Base, const CXXRecordDecl *RD) {
+  for (const auto &B : RD->bases()) {
+    if (B.isVirtual() && B.getType()->getAsCXXRecordDecl() == Base)
+      return true;
+  }
+  return false;
+}
+
 void VFTableBuilder::AddMethods(BaseSubobject Base, unsigned BaseDepth,
                                 const CXXRecordDecl *LastVBase,
                                 BasesSetVectorTy &VisitedBases) {
@@ -2808,7 +2817,7 @@ void VFTableBuilder::AddMethods(BaseSubo
   CharUnits NextBaseOffset;
   if (BaseDepth < WhichVFPtr.PathToBaseWithVPtr.size()) {
     NextBase = WhichVFPtr.PathToBaseWithVPtr[BaseDepth];
-    if (Layout.getVBaseOffsetsMap().count(NextBase)) {
+    if (isDirectVBase(NextBase, RD)) {
       NextLastVBase = NextBase;
       NextBaseOffset = MostDerivedClassLayout.getVBaseClassOffset(NextBase);
     } else {

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp?rev=204786&r1=204785&r2=204786&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp Wed Mar 26 03:12:53 2014
@@ -660,6 +660,21 @@ C c;
 // MANGLING-DAG: @"\01??_7C at pr17748@@6BB at 1@@"
 }
 
+namespace pr19066 {
+struct X : virtual B {};
+
+struct Y : virtual X, B {
+  Y();
+  // CHECK-LABEL: VFTable for 'B' in 'pr19066::X' in 'pr19066::Y' (1 entry).
+  // CHECK-NEXT:  0 | void B::g()
+
+  // CHECK-LABEL: VFTable for 'B' in 'pr19066::Y' (1 entry).
+  // CHECK-NEXT:  0 | void B::g()
+};
+
+Y::Y() {}
+}
+
 namespace pr19240 {
 struct A {
   virtual void c();





More information about the cfe-commits mailing list