1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed issues with chained dtors in extensions

This commit is contained in:
Brian Fiete 2020-10-15 12:05:50 -07:00
parent 3bb94764d2
commit fe7d3d80e7

View file

@ -1877,39 +1877,40 @@ void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* r
while (checkBaseType != NULL) while (checkBaseType != NULL)
{ {
if ((checkBaseType->mTypeDef->mDtorDef != NULL) /*&& (checkBaseType != mContext->mBfObjectType)*/) if ((checkBaseType->mTypeDef->mDtorDef != NULL) /*&& (checkBaseType != mContext->mBfObjectType)*/)
{ {
bool isDynAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsDyn(scopeData));
auto dtorMethodInstance = GetMethodInstance(checkBaseType, checkBaseType->mTypeDef->mDtorDef, BfTypeVector()); auto dtorMethodInstance = GetMethodInstance(checkBaseType, checkBaseType->mTypeDef->mDtorDef, BfTypeVector());
if (dtorMethodInstance)
BfIRValue useVal = val.mValue;
useVal = mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapTypeInstPtr(checkBaseType));
if (isDynAlloc)
{ {
// bool isDynAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsDyn(scopeData));
} BfIRValue useVal = val.mValue;
else if (condAlloca) useVal = mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapTypeInstPtr(checkBaseType));
{
BF_ASSERT(!IsTargetingBeefBackend());
BF_ASSERT(!isDynAlloc);
auto valPtr = CreateAlloca(checkBaseType);
mBfIRBuilder->CreateStore(useVal, valPtr);
useVal = valPtr;
}
SizedArray<BfIRValue, 1> llvmArgs; if (isDynAlloc)
llvmArgs.push_back(useVal); {
auto deferredCall = AddDeferredCall(dtorMethodInstance, llvmArgs, scopeData, refNode, true); //
if (deferredCall != NULL) }
{ else if (condAlloca)
deferredCall->mCastThis = (val.mType != checkBaseType) && (!isDynAlloc); {
if (condAlloca) BF_ASSERT(!IsTargetingBeefBackend());
deferredCall->mArgsNeedLoad = true; BF_ASSERT(!isDynAlloc);
} auto valPtr = CreateAlloca(checkBaseType);
hadDtorCall = true; mBfIRBuilder->CreateStore(useVal, valPtr);
useVal = valPtr;
}
break; SizedArray<BfIRValue, 1> llvmArgs;
llvmArgs.push_back(useVal);
auto deferredCall = AddDeferredCall(dtorMethodInstance, llvmArgs, scopeData, refNode, true);
if (deferredCall != NULL)
{
deferredCall->mCastThis = (val.mType != checkBaseType) && (!isDynAlloc);
if (condAlloca)
deferredCall->mArgsNeedLoad = true;
}
hadDtorCall = true;
break;
}
} }
checkBaseType = checkBaseType->mBaseType; checkBaseType = checkBaseType->mBaseType;
@ -14872,6 +14873,12 @@ void BfModule::EmitDtorBody()
auto fieldDef = fieldInst->GetFieldDef(); auto fieldDef = fieldInst->GetFieldDef();
if ((fieldDef != NULL) && (fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mFieldDtor != NULL)) if ((fieldDef != NULL) && (fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mFieldDtor != NULL))
{ {
if (fieldDef->mDeclaringType != mCurMethodInstance->mMethodDef->mDeclaringType)
{
BF_ASSERT(mCurTypeInstance->mTypeDef->mIsCombinedPartial);
continue;
}
if ((!methodDef->mIsStatic) && (mCurTypeInstance->IsValueType())) if ((!methodDef->mIsStatic) && (mCurTypeInstance->IsValueType()))
{ {
Fail("Structs cannot have field destructors", fieldDef->mFieldDeclaration->mFieldDtor->mTildeToken, true); Fail("Structs cannot have field destructors", fieldDef->mFieldDeclaration->mFieldDtor->mTildeToken, true);
@ -14967,7 +14974,7 @@ void BfModule::EmitDtorBody()
} }
} }
if (!methodDef->mIsStatic) if ((!methodDef->mIsStatic) && (mCurMethodInstance->mChainType != BfMethodChainType_ChainMember))
{ {
auto checkBaseType = mCurTypeInstance->mBaseType; auto checkBaseType = mCurTypeInstance->mBaseType;
while (checkBaseType != NULL) while (checkBaseType != NULL)