mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-03 00:20:40 +03:00
Use typed gep in classes.cpp
(#4091)
This logic should be merge with toir.cpp:visit(TypeidExp *e)
This commit is contained in:
parent
f2155c6dd9
commit
fc71e6a937
1 changed files with 8 additions and 4 deletions
|
@ -409,7 +409,8 @@ LLValue *DtoVirtualFunctionPointer(DValue *inst, FuncDeclaration *fdecl) {
|
||||||
// sanity checks
|
// sanity checks
|
||||||
assert(fdecl->isVirtual());
|
assert(fdecl->isVirtual());
|
||||||
assert(!fdecl->isFinalFunc());
|
assert(!fdecl->isFinalFunc());
|
||||||
assert(inst->type->toBasetype()->ty == TY::Tclass);
|
TypeClass * tc = inst->type->toBasetype()->isTypeClass();
|
||||||
|
assert(tc);
|
||||||
// slot 0 is always ClassInfo/Interface* unless it is a CPP class
|
// slot 0 is always ClassInfo/Interface* unless it is a CPP class
|
||||||
assert(fdecl->vtblIndex > 0 ||
|
assert(fdecl->vtblIndex > 0 ||
|
||||||
(fdecl->vtblIndex == 0 &&
|
(fdecl->vtblIndex == 0 &&
|
||||||
|
@ -419,15 +420,18 @@ LLValue *DtoVirtualFunctionPointer(DValue *inst, FuncDeclaration *fdecl) {
|
||||||
LLValue *vthis = DtoRVal(inst);
|
LLValue *vthis = DtoRVal(inst);
|
||||||
IF_LOG Logger::cout() << "vthis: " << *vthis << '\n';
|
IF_LOG Logger::cout() << "vthis: " << *vthis << '\n';
|
||||||
|
|
||||||
|
IrClass * irc = getIrAggr(tc->sym, true);
|
||||||
LLValue *funcval = vthis;
|
LLValue *funcval = vthis;
|
||||||
// get the vtbl for objects
|
// get the vtbl for objects
|
||||||
funcval = DtoGEP(funcval, 0u, 0);
|
llvm::GlobalVariable* vtblsym = irc->getVtblSymbol();
|
||||||
|
funcval = DtoGEP(irc->getLLStructType(), funcval, 0u, 0);
|
||||||
// load vtbl ptr
|
// load vtbl ptr
|
||||||
funcval = DtoLoad(funcval);
|
funcval = DtoLoad(vtblsym->getType(), funcval);
|
||||||
// index vtbl
|
// index vtbl
|
||||||
const std::string name = fdecl->toChars();
|
const std::string name = fdecl->toChars();
|
||||||
const auto vtblname = name + "@vtbl";
|
const auto vtblname = name + "@vtbl";
|
||||||
funcval = DtoGEP(funcval, 0, fdecl->vtblIndex, vtblname.c_str());
|
funcval = DtoGEP(vtblsym->getValueType(),
|
||||||
|
funcval, 0, fdecl->vtblIndex, vtblname.c_str());
|
||||||
// load opaque pointer
|
// load opaque pointer
|
||||||
funcval = DtoAlignedLoad(getVoidPtrType(), funcval);
|
funcval = DtoAlignedLoad(getVoidPtrType(), funcval);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue