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

Mike Stump mrs at apple.com
Thu Aug 6 14:49:36 PDT 2009


Author: mrs
Date: Thu Aug  6 16:49:36 2009
New Revision: 78343

URL: http://llvm.org/viewvc/llvm-project?rev=78343&view=rev
Log:
Also generate the rtti field for virtual bases for vtables.  Turn on
rtti so we can properly test it.  Refactor code a little.  Still a
work 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=78343&r1=78342&r2=78343&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Aug  6 16:49:36 2009
@@ -514,10 +514,10 @@
   llvm::GlobalVariable::LinkageTypes linktype;
   linktype = llvm::GlobalValue::WeakAnyLinkage;
   std::vector<llvm::Constant *> info;
-  assert (0 && "FIXME: implement rtti descriptor");
+  // assert (0 && "FIXME: implement rtti descriptor");
   // FIXME: descriptor
   info.push_back(llvm::Constant::getNullValue(Ptr8Ty));
-  assert (0 && "FIXME: implement rtti ts");
+  // assert (0 && "FIXME: implement rtti ts");
   // FIXME: TS
   info.push_back(llvm::Constant::getNullValue(Ptr8Ty));
 
@@ -531,14 +531,43 @@
 }
 
 void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
-                                       std::vector<llvm::Constant *> &methods) {
+                                            const CXXRecordDecl *Class,
+                                            llvm::Constant *rtti,
+                                         std::vector<llvm::Constant *> &methods,
+                                            bool isPrimary) {
   typedef CXXRecordDecl::method_iterator meth_iter;
   llvm::Type *Ptr8Ty;
   Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
+  llvm::Constant *m = llvm::Constant::getNullValue(Ptr8Ty);
+
+  if (RD && !RD->isDynamicClass())
+    return;
+  if (RD) {
+    const ASTRecordLayout &Layout = getContext().getASTRecordLayout(Class);
+    int64_t BaseOffset = -(Layout.getBaseClassOffset(RD) / 8);
+    m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset);
+    m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
+  }
+  methods.push_back(m);
+  methods.push_back(rtti);
+
+  if (RD)
+    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 (!isPrimary)
+    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;
        ++mi) {
     if (mi->isVirtual()) {
-      llvm::Constant *m;
       m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
       m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
       methods.push_back(m);
@@ -559,29 +588,19 @@
   linktype = llvm::GlobalValue::WeakAnyLinkage;
   std::vector<llvm::Constant *> methods;
   typedef CXXRecordDecl::method_iterator meth_iter;
-  llvm::Constant *m;
   llvm::Type *Ptr8Ty;
   Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
-  m = llvm::Constant::getNullValue(Ptr8Ty);
   int64_t Offset = 0;
-  methods.push_back(m); Offset += LLVMPointerWidth;
-  methods.push_back(GenerateRtti(RD)); Offset += LLVMPointerWidth;
+  llvm::Constant *rtti = GenerateRtti(RD);
+
+  Offset += LLVMPointerWidth;
+  Offset += LLVMPointerWidth;
 
   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);
-    }
-  }
-
+  GenerateVtableForBase(PrimaryBase, RD, rtti, methods, true);
   for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
          e = RD->bases_end(); i != e; ++i) {
     if (i->isVirtual())
@@ -589,15 +608,7 @@
     const CXXRecordDecl *Base = 
       cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
     if (PrimaryBase != Base) {
-      const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
-      int64_t BaseOffset = -(Layout.getBaseClassOffset(Base) / 8);
-      m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset);
-      m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
-      methods.push_back(m);
-      // FIXME: GenerateRtti for Base in RD.
-      m = llvm::Constant::getNullValue(Ptr8Ty);
-      methods.push_back(m);
-      GenerateVtableForBase(Base, methods);
+      GenerateVtableForBase(Base, RD, rtti, methods);
     }
   }
 
@@ -608,7 +619,7 @@
     const CXXRecordDecl *Base = 
       cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
     if (Base != PrimaryBase)
-      GenerateVtableForBase(Base, methods);
+      GenerateVtableForBase(Base, RD, rtti, methods);
   }
 
   llvm::Constant *C;

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Aug  6 16:49:36 2009
@@ -360,7 +360,10 @@
 
   llvm::Constant *GenerateRtti(const CXXRecordDecl *RD);
   void GenerateVtableForBase(const CXXRecordDecl *RD,
-                             std::vector<llvm::Constant *> &methods);
+                             const CXXRecordDecl *Class,
+                             llvm::Constant *rtti,
+                             std::vector<llvm::Constant *> &methods,
+                             bool isPrimary = 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=78343&r1=78342&r2=78343&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Thu Aug  6 16:49:36 2009
@@ -1,6 +1,6 @@
-// RUN: clang-cc -triple x86_64-apple-darwin -frtti=0 -std=c++0x -O3 -S %s -o %t-64.s &&
+// RUN: clang-cc -triple x86_64-apple-darwin -std=c++0x -O3 -S %s -o %t-64.s &&
 // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s &&
-// RUN: clang-cc -triple i386-apple-darwin -frtti=0 -std=c++0x -O3 -S %s -o %t-32.s &&
+// RUN: clang-cc -triple i386-apple-darwin -std=c++0x -O3 -S %s -o %t-32.s &&
 // RUN: FileCheck -check-prefix LP32 -input-file=%t-32.s %s &&
 // RUN: true
 
@@ -83,37 +83,37 @@
 
 // CHECK-LP64: __ZTV1B:
 // CHECK-LP64: .space 8
-// CHECK-LP64: .space 8
+// CHECK-LP64: .quad __ZTI1B
 // CHECK-LP64: .quad __ZN1B4bar1Ev
 // CHECK-LP64: .quad __ZN1B4bar2Ev
 
 // CHECK-LP32: __ZTV1B:
 // CHECK-LP32: .space 4
-// CHECK-LP32: .space 4
+// CHECK-LP32: .long __ZTI1B
 // CHECK-LP32: .long __ZN1B4bar1Ev
 // CHECK-LP32: .long __ZN1B4bar2Ev
 
 // CHECK-LP64: __ZTV1A:
 // CHECK-LP64: .space 8
-// CHECK-LP64: .space 8
+// CHECK-LP64: .quad __ZTI1A
 // CHECK-LP64: .quad __ZN1B4bar1Ev
 // CHECK-LP64: .quad __ZN1B4bar2Ev
 // CHECK-LP64: .quad __ZN1A4foo1Ev
 // CHECK-LP64: .quad __ZN1A4foo2Ev
 // CHECK-LP64: .quad 18446744073709551600
-// CHECK-LP64: .space 8
+// CHECK-LP64: .quad __ZTI1A
 // CHECK-LP64: .quad __ZN1C4bee1Ev
 // CHECK-LP64: .quad __ZN1C4bee2Ev
 
 // CHECK-LP32: __ZTV1A:
 // CHECK-LP32: .space 4
-// CHECK-LP32: .space 4
+// CHECK-LP32: .long __ZTI1A
 // CHECK-LP32: .long __ZN1B4bar1Ev
 // CHECK-LP32: .long __ZN1B4bar2Ev
 // CHECK-LP32: .long __ZN1A4foo1Ev
 // CHECK-LP32: .long __ZN1A4foo2Ev
 // CHECK-LP32: .long 4294967284
-// CHECK-LP32: .space 4
+// CHECK-LP32: .long __ZTI1A
 // CHECK-LP32: .long __ZN1C4bee1Ev
 // CHECK-LP32: .long __ZN1C4bee2Ev
 
@@ -122,12 +122,12 @@
 // CHECK-LP32 .long 8
 // CHECK-LP32 .space 4
 // CHECK-LP32: .space 4
-// CHECK-LP32: .space 4
+// CHECK-LP32: .long __ZTI1F
 // CHECK-LP32: .long __ZN1D3booEv
 // CHECK-LP32: .long __ZN1F3fooEv
 // CHECK-LP32 .space 4
 // CHECK-LP32 .long -8
-// CHECK-LP32 .space 4
+// CHECK-LP32: .long __ZTI1F
 // CHECK-LP32: .long __ZN2D13barEv
 
 // CHECK-LP64: __ZTV1F:
@@ -135,10 +135,10 @@
 // CHECK-LP64 .quad 16
 // CHECK-LP64 .space 8
 // CHECK-LP64: .space 8
-// CHECK-LP64: .space 8
+// CHECK-LP64: .quad __ZTI1F
 // CHECK-LP64: .quad __ZN1D3booEv
 // CHECK-LP64: .quad __ZN1F3fooEv
 // CHECK-LP64 .space 8
 // CHECK-LP64 .space -16
-// CHECK-LP64 .space 8
+// CHECK-LP64:.quad __ZTI1F
 // CHECK-LP64: .quad __ZN2D13barEv





More information about the cfe-commits mailing list