diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-07-28 17:38:28 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-07-28 17:38:28 +0000 |
commit | 9e809e7da2448c08aa11f15be4680226754678ce (patch) | |
tree | 80da38d384657efa4f61e14563f8296541f7999d /lib/CodeGen/CGCXX.cpp | |
parent | 227aad58cc46c15dfc3fee2244d4a56d8c003d8f (diff) |
More work toward data member access ir-gen.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77332 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index dd32cad21b..a0aaa82b4b 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -155,6 +155,42 @@ llvm::Value *CodeGenFunction::LoadCXXThis() { return Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this"); } +llvm::Value *CodeGenFunction::AddressCXXOfBaseClass(llvm::Value *BaseValue, + CXXRecordDecl *ClassDecl, + CXXRecordDecl *BaseClassDecl) { + if (ClassDecl == BaseClassDecl) + return BaseValue; + + // 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 = VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty); + unsigned Idx = 0; + for (CXXRecordDecl::base_class_const_iterator i = + ClassDecl->bases_begin(), + e = ClassDecl->bases_end(); i != e; ++i, ++Idx) { + if (!i->isVirtual()) { + const CXXRecordDecl *Base = + cast<CXXRecordDecl>(i->getType()->getAsRecordType()->getDecl()); + if (Base == BaseClassDecl) + break; + } + } + uint64_t Offset = Layout.getFieldOffset(Idx) / 8; + llvm::Value *OffsetVal = llvm::ConstantInt::get(llvm::Type::Int32Ty, Offset); + BaseValue = Builder.CreateBitCast(BaseValue, I8Ptr); + BaseValue = Builder.CreateGEP(BaseValue, OffsetVal, "add.ptr"); + QualType BTy = + getContext().getCanonicalType( + getContext().getTypeDeclType(BaseClassDecl)); + const llvm::Type *BasePtr = ConvertType(BTy); + BasePtr = VMContext.getPointerTypeUnqual(BasePtr); + BaseValue = Builder.CreateBitCast(BaseValue, BasePtr); + return BaseValue; +} + void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, |