Skip to content

Commit df19079

Browse files
committed
[add assertions for DFuncValue types]
1 parent cd03f54 commit df19079

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

gen/dvalue.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ LLValue *DSliceValue::getPtr() {
108108
DFuncValue::DFuncValue(Type *t, FuncDeclaration *fd, LLValue *funcPtr,
109109
LLValue *vt, LLValue *vtable)
110110
: DRValue(t, funcPtr), func(fd), funcPtr(funcPtr), vthis(vt),
111-
vtable(vtable) {}
111+
vtable(vtable) {
112+
const auto tb = t->toBasetype();
113+
assert(tb->ty == TY::Tfunction || tb->ty == TY::Tdelegate ||
114+
(tb->ty == TY::Tpointer &&
115+
tb->nextOf()->toBasetype()->ty == TY::Tfunction));
116+
}
112117

113118
DFuncValue::DFuncValue(FuncDeclaration *fd, LLValue *funcPtr, LLValue *vt,
114119
LLValue *vtable)

gen/llvmhelpers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ DValue *DtoSymbolAddress(const Loc &loc, Type *type, Declaration *decl) {
15381538
// to the module member list.
15391539
DtoDefineFunction(flitdecl);
15401540

1541-
return new DFuncValue(flitdecl, DtoCallee(flitdecl, false));
1541+
return new DFuncValue(type, flitdecl, DtoCallee(flitdecl, false));
15421542
}
15431543

15441544
if (FuncDeclaration *fdecl = decl->isFuncDeclaration()) {
@@ -1555,7 +1555,7 @@ DValue *DtoSymbolAddress(const Loc &loc, Type *type, Declaration *decl) {
15551555
}
15561556
DtoResolveFunction(fdecl);
15571557
assert(!DtoIsMagicIntrinsic(fdecl));
1558-
return new DFuncValue(fdecl, DtoCallee(fdecl));
1558+
return new DFuncValue(type, fdecl, DtoCallee(fdecl));
15591559
}
15601560

15611561
if (SymbolDeclaration *sdecl = decl->isSymbolDeclaration()) {

gen/toir.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ class ToElemVisitor : public Visitor {
10861086
assert(funcPtr);
10871087

10881088
LLValue *vthis = (DtoIsInMemoryOnly(l->type) ? DtoLVal(l) : DtoRVal(l));
1089-
result = new DFuncValue(fdecl, funcPtr, vthis, vtable);
1089+
result = new DFuncValue(e->type, fdecl, funcPtr, vthis, vtable);
10901090
} else {
10911091
llvm_unreachable("Unknown target for VarDeclaration.");
10921092
}

0 commit comments

Comments
 (0)