From fc71e6a937f73b963f8daa9a91f51de7ab30a60e Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Thu, 1 Sep 2022 17:15:13 +0800 Subject: [PATCH] Use typed gep in `classes.cpp` (#4091) This logic should be merge with toir.cpp:visit(TypeidExp *e) --- gen/classes.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gen/classes.cpp b/gen/classes.cpp index e65dc072fe..ba6e9aec53 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -409,7 +409,8 @@ LLValue *DtoVirtualFunctionPointer(DValue *inst, FuncDeclaration *fdecl) { // sanity checks assert(fdecl->isVirtual()); 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 assert(fdecl->vtblIndex > 0 || (fdecl->vtblIndex == 0 && @@ -419,15 +420,18 @@ LLValue *DtoVirtualFunctionPointer(DValue *inst, FuncDeclaration *fdecl) { LLValue *vthis = DtoRVal(inst); IF_LOG Logger::cout() << "vthis: " << *vthis << '\n'; + IrClass * irc = getIrAggr(tc->sym, true); LLValue *funcval = vthis; // 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 - funcval = DtoLoad(funcval); + funcval = DtoLoad(vtblsym->getType(), funcval); // index vtbl const std::string name = fdecl->toChars(); 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 funcval = DtoAlignedLoad(getVoidPtrType(), funcval);