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

Mike Stump mrs at apple.com
Thu Aug 6 11:05:23 PDT 2009


Author: mrs
Date: Thu Aug  6 13:05:22 2009
New Revision: 78327

URL: http://llvm.org/viewvc/llvm-project?rev=78327&view=rev
Log:
Layout the primary base first in the vtable.

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

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=78327&r1=78326&r2=78327&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Aug  6 13:05:22 2009
@@ -576,6 +576,18 @@
   const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
   const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
 
+  // The primary base comes first.
+  if (PrimaryBase)
+    GenerateVtableForBase(PrimaryBase, methods);
+  for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
+       ++mi) {
+    if (mi->isVirtual()) {
+      m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
+      m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
+      methods.push_back(m);
+    }
+  }
+
   for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
          e = RD->bases_end(); i != e; ++i) {
     if (i->isVirtual())
@@ -591,29 +603,10 @@
       // FIXME: GenerateRtti for Base in RD.
       m = llvm::Constant::getNullValue(Ptr8Ty);
       methods.push_back(m);
-    }
-    GenerateVtableForBase(Base, methods);
-    if (PrimaryBase == Base) {
-      for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
-           ++mi) {
-        if (mi->isVirtual()) {
-          m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
-          m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
-          methods.push_back(m);
-        }
-      }
-    }
-  }
-  if (PrimaryBase == 0) {
-    for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
-         ++mi) {
-      if (mi->isVirtual()) {
-        m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
-        m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
-        methods.push_back(m);
-      }
+      GenerateVtableForBase(Base, methods);
     }
   }
+
   // FIXME: finish layout for virtual bases
   // FIXME: audit indirect virtual bases
   for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),

Modified: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=78327&r1=78326&r2=78327&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Thu Aug  6 13:05:22 2009
@@ -123,8 +123,8 @@
 // CHECK-LP32 .space 4
 // CHECK-LP32: .space 4
 // CHECK-LP32: .space 4
-// CHECK-LP32 .long __ZN1D3booEv
-// CHECK-LP32 .long __ZN1F3fooEv
+// CHECK-LP32: .long __ZN1D3booEv
+// CHECK-LP32: .long __ZN1F3fooEv
 // CHECK-LP32 .space 4
 // CHECK-LP32 .long -8
 // CHECK-LP32 .space 4
@@ -136,10 +136,9 @@
 // CHECK-LP64 .space 8
 // CHECK-LP64: .space 8
 // CHECK-LP64: .space 8
-// CHECK-LP64 .quad __ZN1D3booEv
-// CHECK-LP64 .quad __ZN1F3fooEv
+// CHECK-LP64: .quad __ZN1D3booEv
+// CHECK-LP64: .quad __ZN1F3fooEv
 // CHECK-LP64 .space 8
 // CHECK-LP64 .space -16
 // CHECK-LP64 .space 8
 // CHECK-LP64: .quad __ZN2D13barEv
-





More information about the cfe-commits mailing list