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
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 5ded216..d780824 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -442,18 +442,11 @@
// 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?");