Skip to content

Commit

Permalink
[add assertions for DFuncValue types]
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Sep 25, 2024
1 parent cd03f54 commit df19079
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion gen/dvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ LLValue *DSliceValue::getPtr() {
DFuncValue::DFuncValue(Type *t, FuncDeclaration *fd, LLValue *funcPtr,
LLValue *vt, LLValue *vtable)
: DRValue(t, funcPtr), func(fd), funcPtr(funcPtr), vthis(vt),
vtable(vtable) {}
vtable(vtable) {
const auto tb = t->toBasetype();
assert(tb->ty == TY::Tfunction || tb->ty == TY::Tdelegate ||
(tb->ty == TY::Tpointer &&
tb->nextOf()->toBasetype()->ty == TY::Tfunction));
}

DFuncValue::DFuncValue(FuncDeclaration *fd, LLValue *funcPtr, LLValue *vt,
LLValue *vtable)
Expand Down
4 changes: 2 additions & 2 deletions gen/llvmhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ DValue *DtoSymbolAddress(const Loc &loc, Type *type, Declaration *decl) {
// to the module member list.
DtoDefineFunction(flitdecl);

return new DFuncValue(flitdecl, DtoCallee(flitdecl, false));
return new DFuncValue(type, flitdecl, DtoCallee(flitdecl, false));
}

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

if (SymbolDeclaration *sdecl = decl->isSymbolDeclaration()) {
Expand Down
2 changes: 1 addition & 1 deletion gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ class ToElemVisitor : public Visitor {
assert(funcPtr);

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

0 comments on commit df19079

Please sign in to comment.