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");

View file

@ -18,6 +18,7 @@
class ClassDeclaration;
class CtorDeclaration;
class DValue;
class FuncDeclaration;
class NewExp;
class TypeClass;
@ -28,7 +29,7 @@ void DtoResolveClass(ClassDeclaration *cd);
DValue *DtoNewClass(const Loc &loc, TypeClass *type, NewExp *newexp);
void DtoInitClass(TypeClass *tc, llvm::Value *dst);
void DtoFinalizeClass(const Loc &loc, llvm::Value *inst);
void DtoFinalizeScopeClass(const Loc &loc, llvm::Value *inst, bool hasDtor);
void DtoFinalizeScopeClass(const Loc &loc, DValue* dval, bool hasDtor);
DValue *DtoCastClass(const Loc &loc, DValue *val, Type *to);
DValue *DtoDynamicCastObject(const Loc &loc, DValue *val, Type *to);

View file

@ -1554,7 +1554,7 @@ public:
} else if (auto ve = e->e1->isVarExp()) {
if (auto vd = ve->var->isVarDeclaration()) {
if (vd->onstack()) {
DtoFinalizeScopeClass(e->loc, DtoRVal(dval), vd->onstackWithDtor());
DtoFinalizeScopeClass(e->loc, dval, vd->onstackWithDtor());
onstack = true;
}
}