Merge pull request #723 from jbrodman/refcasting

Allow casting reference types like pointers. See Issue #721.
This commit is contained in:
Dmitry Babokin
2014-01-25 10:14:25 -08:00

View File

@@ -6962,9 +6962,9 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
return ctx->BitCastInst(v, ptype); //, "array_cast_0size"); return ctx->BitCastInst(v, ptype); //, "array_cast_0size");
} }
AssertPos(pos, Type::Equal(toTarget, fromTarget) || // Just bitcast it. See Issue #721
Type::Equal(toTarget, fromTarget->GetAsConstType())); llvm::Value *value = expr->GetValue(ctx);
return expr->GetValue(ctx); return ctx->BitCastInst(value, toType->LLVMType(g->ctx), "refcast");
} }
const StructType *toStruct = CastType<StructType>(toType); const StructType *toStruct = CastType<StructType>(toType);
@@ -7170,6 +7170,14 @@ TypeCastExpr::TypeCheck() {
// allow explicit typecasts between any two different pointer types // allow explicit typecasts between any two different pointer types
return this; return this;
const ReferenceType *fromRef = CastType<ReferenceType>(fromType);
const ReferenceType *toRef = CastType<ReferenceType>(toType);
if (fromRef != NULL && toRef != NULL) {
// allow explicit typecasts between any two different reference types
// Issues #721
return this;
}
const AtomicType *fromAtomic = CastType<AtomicType>(fromType); const AtomicType *fromAtomic = CastType<AtomicType>(fromType);
const AtomicType *toAtomic = CastType<AtomicType>(toType); const AtomicType *toAtomic = CastType<AtomicType>(toType);
const EnumType *fromEnum = CastType<EnumType>(fromType); const EnumType *fromEnum = CastType<EnumType>(fromType);