@@ -64,13 +64,16 @@ DRValue::DRValue(Type *t, LLValue *v) : DValue(t, v) {
6464// //////////////////////////////////////////////////////////////////////////////
6565
6666DImValue::DImValue (Type *t, llvm::Value *v) : DRValue(t, v) {
67- // TODO: get rid of Tfunction exception
67+ #ifndef NDEBUG
68+ const auto tb = t->toBasetype ();
69+ #endif
70+ assert (tb->ty != TY::Tarray && " use DSliceValue for dynamic arrays" );
71+ assert (!tb->isFunction_Delegate_PtrToFunction () &&
72+ " use DFuncValue for function pointers and delegates" );
73+
6874 // v may be an addrspace qualified pointer so strip it before doing a pointer
6975 // equality check.
70- assert (t->toBasetype ()->ty == TY::Tfunction ||
71- stripAddrSpaces (v->getType ()) == DtoType (t));
72- assert (t->toBasetype ()->ty != TY::Tarray &&
73- " use DSliceValue for dynamic arrays" );
76+ assert (stripAddrSpaces (v->getType ()) == DtoType (t));
7477}
7578
7679// //////////////////////////////////////////////////////////////////////////////
@@ -119,12 +122,7 @@ DFuncValue::DFuncValue(Type *t, FuncDeclaration *fd, LLValue *funcPtr,
119122 LLValue *vt, LLValue *vtable)
120123 : DRValue(t, createFuncRValue(t, funcPtr, vt)), func(fd), funcPtr(funcPtr),
121124 vthis(vt), vtable(vtable) {
122- #ifndef NDEBUG
123- const auto tb = t->toBasetype ();
124- #endif
125- assert (tb->ty == TY::Tfunction || tb->ty == TY::Tdelegate ||
126- (tb->ty == TY::Tpointer &&
127- tb->nextOf ()->toBasetype ()->ty == TY::Tfunction));
125+ assert (t->toBasetype ()->isFunction_Delegate_PtrToFunction ());
128126}
129127
130128DFuncValue::DFuncValue (FuncDeclaration *fd, LLValue *funcPtr, LLValue *vt,
@@ -150,8 +148,8 @@ DRValue *DLValue::getRVal() {
150148
151149 LLValue *rval = DtoLoad (DtoMemType (type), val);
152150
153- const auto ty = type->toBasetype ()-> ty ;
154- if (ty == TY::Tbool) {
151+ const auto tb = type->toBasetype ();
152+ if (tb-> ty == TY::Tbool) {
155153 assert (rval->getType () == llvm::Type::getInt8Ty (gIR ->context ()));
156154
157155 if (isOptimizationEnabled ()) {
@@ -164,8 +162,14 @@ DRValue *DLValue::getRVal() {
164162
165163 // truncate to i1
166164 rval = gIR ->ir ->CreateTrunc (rval, llvm::Type::getInt1Ty (gIR ->context ()));
167- } else if (ty == TY::Tarray) {
165+ } else if (tb-> ty == TY::Tarray) {
168166 return new DSliceValue (type, rval);
167+ } else if (tb->isPtrToFunction ()) {
168+ return new DFuncValue (type, nullptr , rval);
169+ } else if (tb->ty == TY::Tdelegate) {
170+ const auto contextPtr = DtoExtractValue (rval, 0 , " .ptr" );
171+ const auto funcPtr = DtoExtractValue (rval, 1 , " .funcptr" );
172+ return new DFuncValue (type, nullptr , funcPtr, contextPtr);
169173 }
170174
171175 return new DImValue (type, rval);
0 commit comments