diff options
author | Anders Carlsson <andersca@mac.com> | 2009-09-12 04:57:16 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-09-12 04:57:16 +0000 |
commit | 191dfe909d6cc18e9134ac23ac4daaedeceb862f (patch) | |
tree | edda7e459a2f57f9d8b726b4a751ff08f66d1cbb /lib/CodeGen | |
parent | 61faec1e9cd1ddaaae9e7216c4b751681af271e4 (diff) |
Handle derived-to-base conversion in CGExprScalar::EmitCast, if the cast kind is CK_DerivedToBase.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81610 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index ef323c14ba..7adbc9fd3b 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -466,17 +466,9 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, // some native types (like Obj-C id) may map to a pointer type. if (isa<llvm::PointerType>(DstTy)) { // The source value may be an integer, or a pointer. - if (isa<llvm::PointerType>(Src->getType())) { - // Some heavy lifting for derived to base conversion. - // FIXME: This should be handled by EmitCast. - if (const CXXRecordDecl *ClassDecl = - SrcType->getCXXRecordDeclForPointerType()) - if (const CXXRecordDecl *BaseClassDecl = - DstType->getCXXRecordDeclForPointerType()) - Src = CGF.GetAddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl, - /*NullCheckValue=*/false); + if (isa<llvm::PointerType>(Src->getType())) return Builder.CreateBitCast(Src, DstTy, "conv"); - } + assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?"); // First, convert to the correct width so that we control the kind of // extension. @@ -665,6 +657,22 @@ Value *ScalarExprEmitter::EmitCastExpr(const Expr *E, QualType DestTy, } case CastExpr::CK_NullToMemberPointer: return CGF.CGM.EmitNullConstant(DestTy); + + case CastExpr::CK_DerivedToBase: { + const RecordType *DerivedClassTy = + E->getType()->getAs<PointerType>()->getPointeeType()->getAs<RecordType>(); + CXXRecordDecl *DerivedClassDecl = + cast<CXXRecordDecl>(DerivedClassTy->getDecl()); + + const RecordType *BaseClassTy = + DestTy->getAs<PointerType>()->getPointeeType()->getAs<RecordType>(); + CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(BaseClassTy->getDecl()); + + Value *Src = Visit(const_cast<Expr*>(E)); + return CGF.GetAddressCXXOfBaseClass(Src, DerivedClassDecl, BaseClassDecl, + /*NullCheckValue=*/true); + } + } // Handle cases where the source is an non-complex type. |