[PATCH] Fix PR19066 - 0-sized vftable in the presence of virtual inheritance
Timur Iskhodzhanov
timurrrr at google.com
Tue Mar 25 08:30:39 PDT 2014
Hi rnk, whunt,
Just curious, is there a handy function like isDirectVBase() available somewhere?
http://llvm-reviews.chandlerc.com/D3181
Files:
lib/AST/VTableBuilder.cpp
test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
Index: lib/AST/VTableBuilder.cpp
===================================================================
--- lib/AST/VTableBuilder.cpp
+++ lib/AST/VTableBuilder.cpp
@@ -2531,6 +2531,7 @@
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 @@
return false;
}
+static bool isDirectVBase(const CXXRecordDecl *Base, const CXXRecordDecl *RD) {
+ for (const auto &I : RD->bases()) {
+ if (I.isVirtual() && I.getType()->getAsCXXRecordDecl() == Base)
+ return true;
+ }
+ return false;
+}
+
void VFTableBuilder::AddMethods(BaseSubobject Base, unsigned BaseDepth,
const CXXRecordDecl *LastVBase,
BasesSetVectorTy &VisitedBases) {
@@ -2808,7 +2817,7 @@
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 {
Index: test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
===================================================================
--- test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
+++ test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
@@ -659,3 +659,18 @@
// MANGLING-DAG: @"\01??_7C at pr17748@@6BA at 1@@"
// 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() {}
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3181.1.patch
Type: text/x-patch
Size: 2080 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140325/fd88a045/attachment.bin>
More information about the cfe-commits
mailing list