aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGCXX.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-07-30 00:10:25 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-07-30 00:10:25 +0000
commitc238a79a97ad35227a28acf16028ab63127c2fb7 (patch)
tree295bb8f9d13575f341f5c25f1bc610bda38d5505 /lib/CodeGen/CGCXX.cpp
parentdbb8d81df3477f37657be53f6df56279a61e2e5f (diff)
ir-gen for nested non-virtual base member access
in current class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r--lib/CodeGen/CGCXX.cpp52
1 files changed, 47 insertions, 5 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index f80956b93f..bce22e5ec3 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -155,19 +155,61 @@ llvm::Value *CodeGenFunction::LoadCXXThis() {
return Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this");
}
+static bool
+GetNestedPaths(llvm::SmallVectorImpl<const CXXRecordDecl *> &NestedBasePaths,
+ const CXXRecordDecl *ClassDecl,
+ const CXXRecordDecl *BaseClassDecl) {
+ assert(!ClassDecl->isPolymorphic() &&
+ "FIXME: We don't support polymorphic classes yet!");
+ for (CXXRecordDecl::base_class_const_iterator i = ClassDecl->bases_begin(),
+ e = ClassDecl->bases_end(); i != e; ++i) {
+ if (i->isVirtual())
+ continue;
+ const CXXRecordDecl *Base =
+ cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+ if (Base == BaseClassDecl) {
+ NestedBasePaths.push_back(BaseClassDecl);
+ return true;
+ }
+ }
+ // BaseClassDecl not an immediate base of ClassDecl.
+ for (CXXRecordDecl::base_class_const_iterator i = ClassDecl->bases_begin(),
+ e = ClassDecl->bases_end(); i != e; ++i) {
+ if (i->isVirtual())
+ continue;
+ const CXXRecordDecl *Base =
+ cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+ if (GetNestedPaths(NestedBasePaths, Base, BaseClassDecl)) {
+ NestedBasePaths.push_back(Base);
+ return true;
+ }
+ }
+ return false;
+}
+
llvm::Value *CodeGenFunction::AddressCXXOfBaseClass(llvm::Value *BaseValue,
const CXXRecordDecl *ClassDecl,
const CXXRecordDecl *BaseClassDecl) {
if (ClassDecl == BaseClassDecl)
return BaseValue;
+ llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
+ llvm::SmallVector<const CXXRecordDecl *, 16> NestedBasePaths;
+ GetNestedPaths(NestedBasePaths, ClassDecl, BaseClassDecl);
+ assert(NestedBasePaths.size() > 0 &&
+ "AddressCXXOfBaseClass - inheritence path failed");
+ NestedBasePaths.push_back(ClassDecl);
+ uint64_t Offset = 0;
+
// Accessing a member of the base class. Must add delata to
// the load of 'this'.
- // FIXME. Once type layout is complete, this will probably change.
- const ASTRecordLayout &Layout =
- getContext().getASTRecordLayout(ClassDecl);
- llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
- uint64_t Offset = Layout.getBaseClassOffset(BaseClassDecl) / 8;
+ for (unsigned i = NestedBasePaths.size()-1; i > 0; i--) {
+ const CXXRecordDecl *DerivedClass = NestedBasePaths[i];
+ const CXXRecordDecl *BaseClass = NestedBasePaths[i-1];
+ const ASTRecordLayout &Layout =
+ getContext().getASTRecordLayout(DerivedClass);
+ Offset += Layout.getBaseClassOffset(BaseClass) / 8;
+ }
llvm::Value *OffsetVal =
llvm::ConstantInt::get(
CGM.getTypes().ConvertType(CGM.getContext().LongTy), Offset);