Use typed gep in DtoFinalizeScopeClass (#4081)

This commit is contained in:
Nicholas Wilson 2022-08-31 11:14:23 +08:00 committed by GitHub
parent a79a30c41e
commit d8d105fb1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View file

@ -188,7 +188,8 @@ void DtoFinalizeClass(const Loc &loc, LLValue *inst) {
////////////////////////////////////////////////////////////////////////////////
void DtoFinalizeScopeClass(const Loc &loc, LLValue *inst, bool hasDtor) {
void DtoFinalizeScopeClass(const Loc &loc, DValue* dval, bool hasDtor) {
llvm::Value* inst = DtoRVal(dval);
if (!isOptimizationEnabled() || hasDtor) {
DtoFinalizeClass(loc, inst);
return;
@ -199,7 +200,9 @@ void DtoFinalizeScopeClass(const Loc &loc, LLValue *inst, bool hasDtor) {
llvm::BasicBlock *ifbb = gIR->insertBB("if");
llvm::BasicBlock *endbb = gIR->insertBBAfter(ifbb, "endif");
const auto monitor = DtoLoad(DtoGEP(inst, 0, 1), ".monitor");
llvm::StructType *st = getIrAggr(static_cast<TypeClass *>(dval->type)->sym)
->getLLStructType();
const auto monitor = DtoLoad(st->getElementType(1), DtoGEP(st, inst, 0, 1), ".monitor");
const auto hasMonitor =
gIR->ir->CreateICmp(llvm::CmpInst::ICMP_NE, monitor,
getNullValue(monitor->getType()), ".hasMonitor");