From 8b2d2fe234163745794605ef643d60f0c4875207 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 7 Aug 2010 11:51:51 +0000 Subject: Allow reference binding of a reference of Objective-C object type to an lvalue of another, compatible Objective-C object type (e.g., a subclass). Introduce a new initialization sequence step kind to describe this binding, along with a new cast kind. Fixes PR7741. llvm-svn: 110513 --- clang/lib/CodeGen/CGExpr.cpp | 7 +++++++ clang/lib/CodeGen/CGExprScalar.cpp | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 9424776898b..e2ccf55f937 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1851,6 +1851,13 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { ConvertType(CE->getTypeAsWritten())); return LValue::MakeAddr(V, MakeQualifiers(E->getType())); } + case CastExpr::CK_ObjCObjectLValueCast: { + LValue LV = EmitLValue(E->getSubExpr()); + QualType ToType = getContext().getLValueReferenceType(E->getType()); + llvm::Value *V = Builder.CreateBitCast(LV.getAddress(), + ConvertType(ToType)); + return LValue::MakeAddr(V, MakeQualifiers(E->getType())); + } } llvm_unreachable("Unhandled lvalue cast kind?"); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index dbafd2bffe8..c9e4dbd1405 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -925,7 +925,8 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) { //assert(0 && "Unknown cast kind!"); break; - case CastExpr::CK_LValueBitCast: { + case CastExpr::CK_LValueBitCast: + case CastExpr::CK_ObjCObjectLValueCast: { Value *V = EmitLValue(E).getAddress(); V = Builder.CreateBitCast(V, ConvertType(CGF.getContext().getPointerType(DestTy))); @@ -1044,7 +1045,10 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) { return Builder.CreatePtrToInt(Src, ConvertType(DestTy)); } case CastExpr::CK_ToVoid: { - CGF.EmitAnyExpr(E, 0, false, true); + if (E->Classify(CGF.getContext()).isGLValue()) + CGF.EmitLValue(E); + else + CGF.EmitAnyExpr(E, 0, false, true); return 0; } case CastExpr::CK_VectorSplat: { -- cgit v1.2.3