[cfe-commits] r79506 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/virt.cpp
Mike Stump
mrs at apple.com
Wed Aug 19 19:11:48 PDT 2009
Author: mrs
Date: Wed Aug 19 21:11:48 2009
New Revision: 79506
URL: http://llvm.org/viewvc/llvm-project?rev=79506&view=rev
Log:
Ensure we don't output repeated vbase offsets. I have a testcase for
this, but need to fixup the actual offset value before I can check it
in. WIP.
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=79506&r1=79505&r2=79506&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Aug 19 21:11:48 2009
@@ -788,6 +788,7 @@
const CXXRecordDecl *Class;
const ASTRecordLayout &BLayout;
llvm::SmallSet<const CXXRecordDecl *, 32> IndirectPrimary;
+ llvm::SmallSet<const CXXRecordDecl *, 32> SeenVBase;
llvm::Constant *rtti;
llvm::LLVMContext &VMContext;
CodeGenModule &CGM; // Per-module state.
@@ -829,6 +830,25 @@
}
}
+ void GenerateVBaseOffsets(std::vector<llvm::Constant *> &offsets,
+ const CXXRecordDecl *RD,
+ uint64_t Offset, const ASTRecordLayout &Layout) {
+ for (CXXRecordDecl::base_class_const_iterator i =RD->bases_begin(),
+ e = RD->bases_end(); i != e; ++i) {
+ const CXXRecordDecl *Base =
+ cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+ if (i->isVirtual() && !SeenVBase.count(Base)) {
+ SeenVBase.insert(Base);
+ int64_t BaseOffset = Offset/8 + Layout.getVBaseClassOffset(Base) / 8;
+ llvm::Constant *m;
+ m = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), BaseOffset);
+ m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
+ offsets.push_back(m);
+ }
+ GenerateVBaseOffsets(offsets, Base, Offset, Layout);
+ }
+ }
+
void GenerateMethods(const CXXRecordDecl *RD) {
llvm::Constant *m;
@@ -864,9 +884,8 @@
// The virtual base offsets come first...
// FIXME: Audit, is this right?
if (PrimaryBase == 0 || forPrimary || !PrimaryBaseWasVirtual) {
- llvm::SmallSet<const CXXRecordDecl *, 32> SeenVBase;
std::vector<llvm::Constant *> offsets;
- GenerateVBaseOffsets(offsets, RD, SeenVBase, Offset, Layout);
+ GenerateVBaseOffsets(offsets, RD, Offset, Layout);
for (std::vector<llvm::Constant *>::reverse_iterator i = offsets.rbegin(),
e = offsets.rend(); i != e; ++i)
methods.push_back(*i);
@@ -907,6 +926,7 @@
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
if (Base != PrimaryBase || PrimaryBaseWasVirtual) {
uint64_t o = Offset + Layout.getBaseClassOffset(Base);
+ SeenVBase.clear();
GenerateVtableForBase(Base, true, false, o, false);
}
}
@@ -921,32 +941,13 @@
if (i->isVirtual() && !IndirectPrimary.count(Base)) {
// Mark it so we don't output it twice.
IndirectPrimary.insert(Base);
+ SeenVBase.clear();
GenerateVtableForBase(Base, false, true, 0, true);
}
if (Base->getNumVBases())
GenerateVtableForVBases(Base, Class);
}
}
-
- void GenerateVBaseOffsets(std::vector<llvm::Constant *> &offsets,
- const CXXRecordDecl *RD,
- llvm::SmallSet<const CXXRecordDecl *, 32> &SeenVBase,
- uint64_t Offset, const ASTRecordLayout &Layout) {
- for (CXXRecordDecl::base_class_const_iterator i =RD->bases_begin(),
- e = RD->bases_end(); i != e; ++i) {
- const CXXRecordDecl *Base =
- cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
- if (i->isVirtual() && !SeenVBase.count(Base)) {
- SeenVBase.insert(Base);
- int64_t BaseOffset = Offset/8 + Layout.getVBaseClassOffset(Base) / 8;
- llvm::Constant *m;
- m = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), BaseOffset);
- m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
- offsets.push_back(m);
- }
- GenerateVBaseOffsets(offsets, Base, SeenVBase, Offset, Layout);
- }
- }
};
llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
Modified: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=79506&r1=79505&r2=79506&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Wed Aug 19 21:11:48 2009
@@ -341,7 +341,7 @@
// CHECK-LP32-NEXT: .long __ZN8test8_B19ftest8_B1Ev
// CHECK-LP32-NEXT: .long 20
// CHECK-LP32-NEXT: .long 12
-// CHECK-LP32: .long 4294967292
+// CHECK-LP32-NEXT: .long 4294967292
// CHECK-LP32-NEXT: .long __ZTI7test8_D
// CHECK-LP32-NEXT: .long __ZN9test8_B2a10ftest8_B2aEv
// CHECK-LP32-NEXT: .long __ZN8test8_B29ftest8_B2Ev
@@ -368,7 +368,7 @@
// CHECK-LP64-NEXT: .quad __ZN8test8_B19ftest8_B1Ev
// CHECK-LP64-NEXT: .quad 40
// CHECK-LP64-NEXT: .quad 24
-// CHECK-LP64: .quad 18446744073709551608
+// CHECK-LP64-NEXT: .quad 18446744073709551608
// CHECK-LP64-NEXT: .quad __ZTI7test8_D
// CHECK-LP64-NEXT: .quad __ZN9test8_B2a10ftest8_B2aEv
// CHECK-LP64-NEXT: .quad __ZN8test8_B29ftest8_B2Ev
More information about the cfe-commits
mailing list