[cfe-commits] r129252 - in /cfe/trunk: lib/CodeGen/CGVTables.cpp test/CodeGenCXX/vtable-layout.cpp

Anders Carlsson andersca at mac.com
Sun Apr 10 11:00:32 PDT 2011


Author: andersca
Date: Sun Apr 10 13:00:32 2011
New Revision: 129252

URL: http://llvm.org/viewvc/llvm-project?rev=129252&view=rev
Log:
Change CollectPrimaryBases to collect the bases in the right order. Fixes one half of PR9660.

Modified:
    cfe/trunk/lib/CodeGen/CGVTables.cpp
    cfe/trunk/test/CodeGenCXX/vtable-layout.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=129252&r1=129251&r2=129252&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Sun Apr 10 13:00:32 2011
@@ -2306,14 +2306,16 @@
 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) {

Modified: cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-layout.cpp?rev=129252&r1=129251&r2=129252&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Sun Apr 10 13:00:32 2011
@@ -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 @@
 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; }
+
+}





More information about the cfe-commits mailing list