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

Mike Stump mrs at apple.com
Thu Aug 6 08:50:11 PDT 2009


Author: mrs
Date: Thu Aug  6 10:50:11 2009
New Revision: 78314

URL: http://llvm.org/viewvc/llvm-project?rev=78314&view=rev
Log:
More layout for virtual tables for virtual bases.  Still in progress.

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=78314&r1=78313&r2=78314&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Aug  6 10:50:11 2009
@@ -536,6 +536,22 @@
   return Rtti;
 }
 
+void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
+                                       std::vector<llvm::Constant *> &methods) {
+  typedef CXXRecordDecl::method_iterator meth_iter;
+  llvm::Type *Ptr8Ty;
+  Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
+  for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
+       ++mi) {
+    if (mi->isVirtual()) {
+      llvm::Constant *m;
+      m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
+      m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
+      methods.push_back(m);
+    }
+  }
+}
+
 llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
   llvm::SmallString<256> OutName;
   llvm::raw_svector_ostream Out(OutName);
@@ -576,14 +592,7 @@
       m = llvm::Constant::getNullValue(Ptr8Ty);
       methods.push_back(m);
     }
-    for (meth_iter mi = Base->method_begin(), me = Base->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);
     if (PrimaryBase == Base) {
       for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
            ++mi) {
@@ -605,6 +614,15 @@
       }
     }
   }
+  // FIXME: finish layout for virtual bases
+  // FIXME: audit indirect virtual bases
+  for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
+         e = RD->vbases_end(); i != e; ++i) {
+    const CXXRecordDecl *Base = 
+      cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+    if (Base != PrimaryBase)
+      GenerateVtableForBase(Base, methods);
+  }
 
   llvm::Constant *C;
   llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, methods.size());
@@ -612,7 +630,6 @@
   llvm::Value *vtable = new llvm::GlobalVariable(CGM.getModule(), type, true,
                                                  linktype, C, Name);
   vtable = Builder.CreateBitCast(vtable, Ptr8Ty);
-  // FIXME: finish layout for virtual bases
   vtable = Builder.CreateGEP(vtable,
                              llvm::ConstantInt::get(llvm::Type::Int64Ty,
                                                     Offset/8));

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Aug  6 10:50:11 2009
@@ -359,6 +359,8 @@
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
 
   llvm::Constant *GenerateRtti(const CXXRecordDecl *RD);
+  void GenerateVtableForBase(const CXXRecordDecl *RD,
+                             std::vector<llvm::Constant *> &methods);
   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=78314&r1=78313&r2=78314&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Thu Aug  6 10:50:11 2009
@@ -47,7 +47,7 @@
   // CHECK-LP32: movl $4, __ZZ5test2vE2sz
   // CHECK-LP64: movl $8, __ZZ5test2vE2sz(%rip)
 }
-  
+
 static_assert(sizeof(F) == sizeof(void*)*4, "invalid vbase size");
 
 struct E {
@@ -116,3 +116,30 @@
 // CHECK-LP32: .space 4
 // CHECK-LP32: .long __ZN1C4bee1Ev
 // CHECK-LP32: .long __ZN1C4bee2Ev
+
+// CHECK-LP32: __ZTV1F:
+// CHECK-LP32 .space 4
+// CHECK-LP32 .long 8
+// CHECK-LP32 .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32: .space 4
+// CHECK-LP32 .long __ZN1D3booEv
+// CHECK-LP32 .long __ZN1F3fooEv
+// CHECK-LP32 .space 4
+// CHECK-LP32 .long -8
+// CHECK-LP32 .space 4
+// CHECK-LP32: .long __ZN2D13barEv
+
+// CHECK-LP64: __ZTV1F:
+// CHECK-LP64 .space 8
+// CHECK-LP64 .quad 16
+// CHECK-LP64 .space 8
+// CHECK-LP64: .space 8
+// CHECK-LP64: .space 8
+// 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