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

Mike Stump mrs at apple.com
Thu Aug 6 16:48:32 PDT 2009


Author: mrs
Date: Thu Aug  6 18:48:32 2009
New Revision: 78357

URL: http://llvm.org/viewvc/llvm-project?rev=78357&view=rev
Log:
Add support for vcall generation for vtables for virtual bases.  WIP.

Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    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=78357&r1=78356&r2=78357&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Aug  6 18:48:32 2009
@@ -534,7 +534,8 @@
                                             const CXXRecordDecl *Class,
                                             llvm::Constant *rtti,
                                          std::vector<llvm::Constant *> &methods,
-                                            bool isPrimary) {
+                                            bool isPrimary,
+                                            bool ForVirtualBase) {
   typedef CXXRecordDecl::method_iterator meth_iter;
   llvm::Type *Ptr8Ty;
   Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
@@ -542,6 +543,26 @@
 
   if (RD && !RD->isDynamicClass())
     return;
+
+  if (RD && ForVirtualBase)
+    for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
+         ++mi) {
+      if (mi->isVirtual()) {
+        // FIXME: vcall: offset for virtual base for this function
+        m = llvm::Constant::getNullValue(Ptr8Ty);
+        methods.push_back(m);
+      }
+    }
+  if (isPrimary && ForVirtualBase)
+    for (meth_iter mi = Class->method_begin(),
+           me = Class->method_end(); mi != me; ++mi) {
+      if (mi->isVirtual()) {
+        // FIXME: vcall: offset for virtual base for this function
+        m = llvm::Constant::getNullValue(Ptr8Ty);
+        methods.push_back(m);
+      }
+    }
+
   if (RD) {
     const ASTRecordLayout &Layout = getContext().getASTRecordLayout(Class);
     int64_t BaseOffset = -(Layout.getBaseClassOffset(RD) / 8);
@@ -564,8 +585,7 @@
     return;
 
   // And add the virtuals for the class to the primary vtable.
-  RD = Class;
-  for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
+  for (meth_iter mi = Class->method_begin(), me = Class->method_end(); mi != me;
        ++mi) {
     if (mi->isVirtual()) {
       m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
@@ -619,7 +639,7 @@
     const CXXRecordDecl *Base = 
       cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
     if (Base != PrimaryBase)
-      GenerateVtableForBase(Base, RD, rtti, methods);
+      GenerateVtableForBase(Base, RD, rtti, methods, false, true);
   }
 
   llvm::Constant *C;

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=78357&r1=78356&r2=78357&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Aug  6 18:48:32 2009
@@ -363,7 +363,8 @@
                              const CXXRecordDecl *Class,
                              llvm::Constant *rtti,
                              std::vector<llvm::Constant *> &methods,
-                             bool isPrimary = false);
+                             bool isPrimary = false,
+                             bool ForVirtualBase = false);
   llvm::Value *GenerateVtable(const CXXRecordDecl *RD);
 
   void EmitCtorPrologue(const CXXConstructorDecl *CD);

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

==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Thu Aug  6 18:48:32 2009
@@ -26,6 +26,10 @@
 
 struct D1 {
   virtual void bar();
+  virtual void bar2();
+  virtual void bar3();
+  virtual void bar4();
+  virtual void bar5();
   void *d1;
 };
 void D1::bar() { }
@@ -125,10 +129,18 @@
 // CHECK-LP32: .long __ZTI1F
 // CHECK-LP32: .long __ZN1D3booEv
 // CHECK-LP32: .long __ZN1F3fooEv
-// CHECK-LP32 .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .space 4
 // CHECK-LP32: .long 4294967288
 // CHECK-LP32: .long __ZTI1F
 // CHECK-LP32: .long __ZN2D13barEv
+// CHECK-LP32: .long __ZN2D14bar2Ev
+// CHECK-LP32: .long __ZN2D14bar3Ev
+// CHECK-LP32: .long __ZN2D14bar4Ev
+// CHECK-LP32: .long __ZN2D14bar5Ev
 
 // CHECK-LP64: __ZTV1F:
 // CHECK-LP64 .space 8
@@ -138,7 +150,15 @@
 // CHECK-LP64: .quad __ZTI1F
 // CHECK-LP64: .quad __ZN1D3booEv
 // CHECK-LP64: .quad __ZN1F3fooEv
-// CHECK-LP64 .space 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .space 8
 // CHECK-LP64: .quad 18446744073709551600
 // CHECK-LP64: .quad __ZTI1F
 // CHECK-LP64: .quad __ZN2D13barEv
+// CHECK-LP64: .quad __ZN2D14bar2Ev
+// CHECK-LP64: .quad __ZN2D14bar3Ev
+// CHECK-LP64: .quad __ZN2D14bar4Ev
+// CHECK-LP64: .quad __ZN2D14bar5Ev





More information about the cfe-commits mailing list