[cfe-commits] r81610 - /cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Anders Carlsson
andersca at mac.com
Fri Sep 11 21:57:16 PDT 2009
Author: andersca
Date: Fri Sep 11 23:57:16 2009
New Revision: 81610
URL: http://llvm.org/viewvc/llvm-project?rev=81610&view=rev
Log:
Handle derived-to-base conversion in CGExprScalar::EmitCast, if the cast kind is CK_DerivedToBase.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=81610&r1=81609&r2=81610&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Sep 11 23:57:16 2009
@@ -466,17 +466,9 @@
// 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 @@
}
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.
More information about the cfe-commits
mailing list