1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +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

@ -7651,11 +7651,17 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
else
{
BfArrayType* arrayType = CreateArrayType(type, arrayDim);
auto firstElementField = &arrayType->mFieldInstances.back();
int arrayClassSize = firstElementField->mDataOffset;
sizeValue = GetConstValue(arrayClassSize);
BfIRValue elementDataSize = mBfIRBuilder->CreateMul(GetConstValue(type->GetStride()), arraySize);
sizeValue = mBfIRBuilder->CreateAdd(sizeValue, elementDataSize);
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());