diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-07-29 00:44:13 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-07-29 00:44:13 +0000 |
commit | a91d6a6619a91d0ca7102d8ab5678d855f04d850 (patch) | |
tree | a4a6d23ff32429ce61f5b0ab3d8c32a7af29f895 /lib/CodeGen | |
parent | 87e5732f3307c838fff6adea8ba50147110fe092 (diff) |
Code refactoring to define getCXXRecordDeclForPointerType
and use it in several places.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77411 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 19 | ||||
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 17 |
2 files changed, 14 insertions, 22 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 3a37f2d628..39ef799cd3 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -993,12 +993,10 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) { if (PTy->getPointeeType()->isUnionType()) isUnion = true; CVRQualifiers = PTy->getPointeeType().getCVRQualifiers(); - QualType ClassTy = BaseExpr->getType(); - ClassTy = ClassTy->getPointeeType(); - if (CXXRecordDecl *ClassDecl = - dyn_cast<CXXRecordDecl>(ClassTy->getAsRecordType()->getDecl())) { + if (const CXXRecordDecl *ClassDecl = + BaseExpr->getType()->getCXXRecordDeclForPointerType()) { FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl()); - if (CXXRecordDecl *BaseClassDecl = + if (const CXXRecordDecl *BaseClassDecl = dyn_cast<CXXRecordDecl>(Field->getDeclContext())) BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl); } @@ -1017,14 +1015,15 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) { isNonGC = true; // FIXME: this isn't right for bitfields. BaseValue = BaseLV.getAddress(); - if (BaseExpr->getType()->isUnionType()) + QualType BaseTy = BaseExpr->getType(); + if (BaseTy->isUnionType()) isUnion = true; - CVRQualifiers = BaseExpr->getType().getCVRQualifiers(); - if (CXXRecordDecl *ClassDecl = + CVRQualifiers = BaseTy.getCVRQualifiers(); + if (const CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>( - BaseExpr->getType()->getAsRecordType()->getDecl())) { + BaseTy->getAsRecordType()->getDecl())) { FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl()); - if (CXXRecordDecl *BaseClassDecl = + if (const CXXRecordDecl *BaseClassDecl = dyn_cast<CXXRecordDecl>(Field->getDeclContext())) BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 5ded216f03..d780824632 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -442,18 +442,11 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, // The source value may be an integer, or a pointer. if (isa<llvm::PointerType>(Src->getType())) { // Some heavy lifting for derived to base conversion. - if (const PointerType *PT = SrcType->getAsPointerType()) { - QualType SrcClassTy = PT->getPointeeType(); - if (const RecordType *RT = SrcClassTy->getAsRecordType()) - if (CXXRecordDecl *ClassDecl = - dyn_cast<CXXRecordDecl>(RT->getDecl())) { - QualType DstClassType = DstType->getPointeeType(); - if (const RecordType *DRT = DstClassType->getAsRecordType()) - if (CXXRecordDecl *BaseClassDecl = - dyn_cast<CXXRecordDecl>(DRT->getDecl())) - Src = CGF.AddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl); - } - } + if (const CXXRecordDecl *ClassDecl = + SrcType->getCXXRecordDeclForPointerType()) + if (const CXXRecordDecl *BaseClassDecl = + DstType->getCXXRecordDeclForPointerType()) + Src = CGF.AddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl); return Builder.CreateBitCast(Src, DstTy, "conv"); } assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?"); |