]> granicus.if.org Git - clang/commitdiff
Change CollectPrimaryBases to collect the bases in the right order. Fixes one half...
authorAnders Carlsson <andersca@mac.com>
Sun, 10 Apr 2011 18:00:32 +0000 (18:00 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 10 Apr 2011 18:00:32 +0000 (18:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129252 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGVTables.cpp
test/CodeGenCXX/vtable-layout.cpp

index bc97b7463e8da7818f7c96061e2a66defd49f974..678b115753d800a37de527e8cef4631937dbc619 100644 (file)
@@ -2306,14 +2306,16 @@ void VTableBuilder::dumpLayout(llvm::raw_ostream& Out) {
 static void 
 CollectPrimaryBases(const CXXRecordDecl *RD, ASTContext &Context,
                     VTableBuilder::PrimaryBasesSetVectorTy &PrimaryBases) {
-  while (RD) {
-    const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
-    const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
-    if (PrimaryBase)
-      PrimaryBases.insert(PrimaryBase);
+  const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
+  const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
 
-    RD = PrimaryBase;
-  }
+  if (!PrimaryBase)
+    return;
+
+  CollectPrimaryBases(PrimaryBase, Context, PrimaryBases);
+
+  if (!PrimaryBases.insert(PrimaryBase))
+    assert(false && "Found a duplicate primary base!");
 }
 
 void CodeGenVTables::ComputeMethodVTableIndices(const CXXRecordDecl *RD) {
index 1cf8a52d44b9edcd734d1136255524d9a9c7873a..bd696813c8141d52a8db935011ad494cf082e8fd 100644 (file)
@@ -41,6 +41,7 @@
 // RUN: FileCheck --check-prefix=CHECK-40 %s < %t
 // RUN: FileCheck --check-prefix=CHECK-41 %s < %t
 // RUN: FileCheck --check-prefix=CHECK-42 %s < %t
+// RUN: FileCheck --check-prefix=CHECK-43 %s < %t
 
 // For now, just verify this doesn't crash.
 namespace test0 {
@@ -1679,3 +1680,24 @@ struct D : virtual B, C {
 void D::g() { }
 
 }
+
+namespace Test37 {
+
+// Test that we give C::f the right vtable index. (PR9660).
+struct A {
+       virtual A* f() = 0; 
+};
+
+struct B : virtual A {
+  virtual B* f();
+};
+
+// CHECK-43:      VTable indices for 'Test37::C' (1 entries).
+// CHECK-43-NEXT:    1 | Test37::C *Test37::C::f()
+struct C : B {
+  virtual C* f();
+};
+
+C* C::f() { return 0; }
+
+}