diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index cb7c0935..59b88a34 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -810,6 +810,25 @@ DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to) return new DImValue(to, rval); } +DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to) +{ + LLValue* res = 0; + to = to->toBasetype(); + + if (to->ty == Tdelegate) + { + const LLType* toll = getPtrToType(DtoType(to)); + res = DtoBitCast(val->getRVal(), toll); + } + else + { + error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); + fatal(); + } + + return new DImValue(to, res); +} + DValue* DtoCast(Loc& loc, DValue* val, Type* to) { Type* fromtype = DtoDType(val->getType()); @@ -832,6 +851,9 @@ DValue* DtoCast(Loc& loc, DValue* val, Type* to) else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) { return DtoCastPtr(loc, val, to); } + else if (fromtype->ty == Tdelegate) { + return DtoCastDelegate(loc, val, to); + } else { error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); fatal(); diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index dd1d12d3..10a7ae87 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -48,6 +48,7 @@ DValue* DtoNullValue(Type* t); DValue* DtoCastInt(Loc& loc, DValue* val, Type* to); DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to); DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to); +DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to); DValue* DtoCast(Loc& loc, DValue* val, Type* to); // is template instance check