1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Fixed zero-initialize array of non-aligned-size structs

This commit is contained in:
Brian Fiete 2020-07-31 06:17:47 -07:00
parent 2e656e88f3
commit b544f96bf7
2 changed files with 26 additions and 1 deletions

View file

@ -16408,7 +16408,13 @@ void BfExprEvaluator::InitializedSizedArray(BfSizedArrayType* arrayType, BfToken
members.push_back(defaultVal.mValue);
}
return mModule->mBfIRBuilder->CreateConstArray(mModule->mBfIRBuilder->MapType(checkArrayType), members);
if (checkArrayType->mElementType->IsStruct())
{
// This fixed cases where we have non-size-aligned initializers. Assume zero-initialized
return mModule->mBfIRBuilder->CreateConstStructZero(mModule->mBfIRBuilder->MapType(checkArrayType));
}
else
return mModule->mBfIRBuilder->CreateConstArray(mModule->mBfIRBuilder->MapType(checkArrayType), members);
};
_GetValues(arrayType, openToken, valueExprs, commas, closeToken, false);

View file

@ -1288,6 +1288,25 @@ String BfIRBuilder::ToString(BfIRValue irValue)
BfIRValue targetConst(BfIRValueFlags_Const, ptrToIntConst->mTarget);
return ToString(targetConst) + StrFormat(" PtrToInt TypeCode:%d", ptrToIntConst->mToTypeCode);
}
else if (constant->mConstType == BfConstType_Array)
{
auto constArray = (BfConstantArray*)constant;
String str = ToString(constArray->mType);
str += "(";
for (int i = 0; i < (int)constArray->mValues.size(); i++)
{
if (i > 0)
str += ", ";
str += ToString(constArray->mValues[i]);
}
str += ");";
return str;
}
else if (constant->mConstType == BfConstType_AggZero)
{
return ToString(constant->mIRType) + " zeroinitializer";
}
else
{
BF_FATAL("Unhandled");