Skip to content

Commit 6b7c533

Browse files
committed
DFuncValue: Store LL pair as rvalue for delegates
1 parent df19079 commit 6b7c533

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

gen/dvalue.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,23 @@ LLValue *DSliceValue::getPtr() {
105105

106106
////////////////////////////////////////////////////////////////////////////////
107107

108+
namespace {
109+
LLValue *createFuncRValue(Type *t, LLValue *funcPtr, LLValue *vthis) {
110+
if (t->toBasetype()->ty == TY::Tdelegate) {
111+
assert(vthis);
112+
return DtoAggrPair(vthis, funcPtr);
113+
}
114+
return funcPtr;
115+
}
116+
}
117+
108118
DFuncValue::DFuncValue(Type *t, FuncDeclaration *fd, LLValue *funcPtr,
109119
LLValue *vt, LLValue *vtable)
110-
: DRValue(t, funcPtr), func(fd), funcPtr(funcPtr), vthis(vt),
111-
vtable(vtable) {
120+
: DRValue(t, createFuncRValue(t, funcPtr, vt)), func(fd), funcPtr(funcPtr),
121+
vthis(vt), vtable(vtable) {
122+
#ifndef NDEBUG
112123
const auto tb = t->toBasetype();
124+
#endif
113125
assert(tb->ty == TY::Tfunction || tb->ty == TY::Tdelegate ||
114126
(tb->ty == TY::Tpointer &&
115127
tb->nextOf()->toBasetype()->ty == TY::Tfunction));

gen/toir.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,9 @@ class ToElemVisitor : public Visitor {
947947
// Logger::println("FuncDeclaration");
948948
FuncDeclaration *fd = fv->func;
949949
assert(fd);
950-
result =
951-
fv->type == e->type ? fv : new DFuncValue(e->type, fd, fv->funcPtr);
950+
result = fv->type == e->type
951+
? fv
952+
: new DFuncValue(e->type, fd, fv->funcPtr, fv->vthis);
952953
return;
953954
}
954955
if (v->isIm()) {
@@ -986,9 +987,10 @@ class ToElemVisitor : public Visitor {
986987
if (e->type->toBasetype()->ty == TY::Tfunction) {
987988
DValue *dv = toElem(e->e1);
988989
if (DFuncValue *dfv = dv->isFunc()) {
989-
result = dfv->type == e->type
990-
? dfv
991-
: new DFuncValue(e->type, dfv->func, dfv->funcPtr);
990+
result =
991+
dfv->type == e->type
992+
? dfv
993+
: new DFuncValue(e->type, dfv->func, dfv->funcPtr, dfv->vthis);
992994
} else {
993995
// FIXME: should not reach this
994996
result = new DImValue(e->type, DtoRVal(dv));
@@ -1955,9 +1957,11 @@ class ToElemVisitor : public Visitor {
19551957
DValue *u = toElem(e->e1);
19561958
LLValue *contextptr;
19571959
if (DFuncValue *f = u->isFunc()) {
1958-
assert(f->func);
1959-
// FIXME: use f->vthis
1960-
contextptr = DtoNestedContext(e->loc, f->func);
1960+
contextptr = f->vthis;
1961+
if (!contextptr) {
1962+
assert(f->func);
1963+
contextptr = DtoNestedContext(e->loc, f->func);
1964+
}
19611965
} else {
19621966
contextptr = (DtoIsInMemoryOnly(u->type) ? DtoLVal(u) : DtoRVal(u));
19631967
}
@@ -1993,9 +1997,7 @@ class ToElemVisitor : public Visitor {
19931997
fptr = DtoCallee(e->func);
19941998
}
19951999

1996-
// FIXME: use DFuncValue
1997-
result = new DImValue(
1998-
e->type, DtoAggrPair(DtoType(e->type), contextptr, fptr, ".dg"));
2000+
result = new DFuncValue(e->type, e->func, fptr, contextptr);
19992001
}
20002002

20012003
//////////////////////////////////////////////////////////////////////////////
@@ -2286,11 +2288,11 @@ class ToElemVisitor : public Visitor {
22862288
genFuncLiteral(fd, e);
22872289
LLFunction *callee = DtoCallee(fd, false);
22882290

2289-
if (fd->isNested()) { // FIXME: if e->type->toBasetype() is a Tdelegate?
2291+
if (e->type->toBasetype()->ty == TY::Tdelegate) {
22902292
LLValue *cval = DtoNestedContext(e->loc, fd);
2291-
// FIXME: use DFuncValue
2292-
result = new DImValue(e->type, DtoAggrPair(cval, callee, ".func"));
2293+
result = new DFuncValue(e->type, fd, callee, cval);
22932294
} else {
2295+
assert(!fd->isNested());
22942296
result = new DFuncValue(e->type, fd, callee);
22952297
}
22962298
}

0 commit comments

Comments
 (0)