summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-07-28 18:54:57 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-07-28 18:54:57 +0000
commita399dfae1991f36e6b9930f20908727d0f556c56 (patch)
treeca5d2d150bf06c25768ea80ee1fc2189987a9ff5 /clang
parentd6b4b297062408d74e7dbbdd94a4a640e326ad1f (diff)
downloadbcm5719-llvm-a399dfae1991f36e6b9930f20908727d0f556c56.tar.gz
bcm5719-llvm-a399dfae1991f36e6b9930f20908727d0f556c56.zip
More cleanup of data member access and then some.
llvm-svn: 77351
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGCXX.cpp11
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp24
-rw-r--r--clang/test/CodeGenCXX/constructor-init.cpp3
3 files changed, 28 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index d82b9769519..0b22eb49be8 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/lib/CodeGen/CGCXX.cpp
@@ -168,16 +168,23 @@ llvm::Value *CodeGenFunction::AddressCXXOfBaseClass(llvm::Value *BaseValue,
getContext().getASTRecordLayout(ClassDecl);
llvm::Type *I8Ptr = VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty);
unsigned Idx = 0;
+ bool DerivedToBaseConversion = false;
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;
+ if (Base == BaseClassDecl) {
+ DerivedToBaseConversion = true;
+ break;
+ }
}
}
+ if (!DerivedToBaseConversion) {
+ assert(false && "FIXME - Only derived to imm. base convesion is supported");
+ return BaseValue;
+ }
uint64_t Offset = Layout.getFieldOffset(Idx) / 8;
llvm::Value *OffsetVal = llvm::ConstantInt::get(llvm::Type::Int32Ty, Offset);
BaseValue = Builder.CreateBitCast(BaseValue, I8Ptr);
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index b0e091bd0aa..ab0f9e9c744 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -993,15 +993,14 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
if (PTy->getPointeeType()->isUnionType())
isUnion = true;
CVRQualifiers = PTy->getPointeeType().getCVRQualifiers();
- if (CXXThisExpr *ThisExpr = dyn_cast<CXXThisExpr>(BaseExpr)) {
- QualType ClassTy = ThisExpr->getType();
- ClassTy = ClassTy->getPointeeType();
- CXXRecordDecl *ClassDecl =
- cast<CXXRecordDecl>(ClassTy->getAsRecordType()->getDecl());
+ QualType ClassTy = BaseExpr->getType();
+ ClassTy = ClassTy->getPointeeType();
+ if (CXXRecordDecl *ClassDecl =
+ dyn_cast<CXXRecordDecl>(ClassTy->getAsRecordType()->getDecl())) {
FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
- CXXRecordDecl *BaseClassDecl =
- cast<CXXRecordDecl>(Field->getDeclContext());
- BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
+ if (CXXRecordDecl *BaseClassDecl =
+ dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
+ BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
}
} else if (isa<ObjCPropertyRefExpr>(BaseExpr) ||
isa<ObjCKVCRefExpr>(BaseExpr)) {
@@ -1021,6 +1020,15 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
if (BaseExpr->getType()->isUnionType())
isUnion = true;
CVRQualifiers = BaseExpr->getType().getCVRQualifiers();
+ if (CXXRecordDecl *ClassDecl =
+ dyn_cast<CXXRecordDecl>(
+ BaseExpr->getType()->getAsRecordType()->getDecl())) {
+ FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
+ if (CXXRecordDecl *BaseClassDecl =
+ dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
+ BaseValue =
+ AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
+ }
}
FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
diff --git a/clang/test/CodeGenCXX/constructor-init.cpp b/clang/test/CodeGenCXX/constructor-init.cpp
index 4f7f8ee8c5a..c46a561c308 100644
--- a/clang/test/CodeGenCXX/constructor-init.cpp
+++ b/clang/test/CodeGenCXX/constructor-init.cpp
@@ -38,6 +38,9 @@ struct N : M , P, Q {
printf("iQ = %d\n", iQ);
printf("iP = %d\n", iP);
printf("iM = %d\n", iM);
+ printf("iQ = %d\n", (*this).iQ);
+ printf("iP = %d\n", ((*this)).iP);
+ printf("iM = %d\n", this->iM);
}
float ld;
float ff;
OpenPOWER on IntegriCloud