From 00aeef9f1baa5a1b4dc07df98bc4b0bd471f6409 Mon Sep 17 00:00:00 2001 From: jbrodman Date: Fri, 24 Jan 2014 03:37:27 -0800 Subject: [PATCH] Allow casting reference types like pointers. See Issue #721. --- expr.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/expr.cpp b/expr.cpp index 5be578eb..1b739a9a 100644 --- a/expr.cpp +++ b/expr.cpp @@ -6962,9 +6962,9 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { return ctx->BitCastInst(v, ptype); //, "array_cast_0size"); } - AssertPos(pos, Type::Equal(toTarget, fromTarget) || - Type::Equal(toTarget, fromTarget->GetAsConstType())); - return expr->GetValue(ctx); + // Just bitcast it. See Issue #721 + llvm::Value *value = expr->GetValue(ctx); + return ctx->BitCastInst(value, toType->LLVMType(g->ctx), "refcast"); } const StructType *toStruct = CastType(toType); @@ -7170,6 +7170,14 @@ TypeCastExpr::TypeCheck() { // allow explicit typecasts between any two different pointer types return this; + const ReferenceType *fromRef = CastType(fromType); + const ReferenceType *toRef = CastType(toType); + if (fromRef != NULL && toRef != NULL) { + // allow explicit typecasts between any two different reference types + // Issues #721 + return this; + } + const AtomicType *fromAtomic = CastType(fromType); const AtomicType *toAtomic = CastType(toType); const EnumType *fromEnum = CastType(fromType);