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

Fix for valueless array allocations

This commit is contained in:
Brian Fiete 2020-02-17 14:49:59 -08:00
parent fe531be4ef
commit 6dd49f5d9b
4 changed files with 21 additions and 12 deletions

View file

@ -1397,6 +1397,11 @@ void BeIRCodeGen::HandleNextCmd()
CMD_PARAM(BeType*, type);
CMD_PARAM(BeValue*, arraySize);
if (auto constant = BeValueDynCast<BeConstant>(arraySize))
{
//BF_ASSERT(constant->mInt64 >= 0);
}
auto allocaInst = mBeModule->AllocInst<BeAllocaInst>();
allocaInst->mType = type;
allocaInst->mAlign = type->mAlign;

View file

@ -11279,9 +11279,12 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
}
mModule->mBfIRBuilder->PopulateType(resultType);
if (!resultType->IsValuelessType())
{
mModule->mBfIRBuilder->CreateMemSet(mModule->CreateIndexedValue(resultType, addr, clearFromIdx),
mModule->mBfIRBuilder->CreateConst(BfTypeCode_Int8, isUninit ? 0xCC : 0), clearBytes, resultType->mAlign);
}
}
};
if (resultType->IsVar())

View file

@ -7652,10 +7652,16 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
{
BfArrayType* arrayType = CreateArrayType(type, arrayDim);
auto firstElementField = &arrayType->mFieldInstances.back();
if (!type->IsValuelessType())
{
int arrayClassSize = firstElementField->mDataOffset;
sizeValue = GetConstValue(arrayClassSize);
BfIRValue elementDataSize = mBfIRBuilder->CreateMul(GetConstValue(type->GetStride()), arraySize);
sizeValue = mBfIRBuilder->CreateAdd(sizeValue, elementDataSize);
}
else
sizeValue = GetConstValue(arrayType->mInstSize);
auto prevBlock = mBfIRBuilder->GetInsertBlock();
isDynAlloc = (isDynAlloc) || (!sizeValue.IsConst());

View file

@ -3324,11 +3324,6 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
BF_ASSERT(typeInstance->mInterfaceMethodTable.size() == 1);
}
if (typeInstance->mTypeDef == mCompiler->mPointerTypeDef)
{
NOP;
}
// Slot interfaces method blocks in vtable
{
int ifaceVirtIdx = 0;