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

Sized array encoding fix

This commit is contained in:
Brian Fiete 2021-10-28 09:33:27 -07:00
parent e5e11d52d4
commit e018c08134

View file

@ -3362,7 +3362,17 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta
auto aggConstant = (BfConstantAgg*)constant; auto aggConstant = (BfConstantAgg*)constant;
if (type->IsSizedArray()) if (type->IsSizedArray())
{ {
auto sizedArrayType = (BfSizedArrayType*)type;
for (int i = 0; i < sizedArrayType->mSize; i++)
{
auto fieldConstant = module->mBfIRBuilder->GetConstant(aggConstant->mValues[i]);
if (fieldConstant == NULL)
return false; return false;
if (!WriteConstant(module, addr + i * sizedArrayType->mElementType->mSize, fieldConstant, sizedArrayType->mElementType))
return false;
}
return true;
} }
else if (type->IsArray()) else if (type->IsArray())
{ {
@ -3478,6 +3488,13 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta
return WriteConstant(module, addr, constTarget, type); return WriteConstant(module, addr, constTarget, type);
} }
if (constant->mConstType == BfConstType_BitCastNull)
{
BF_ASSERT(type->IsPointer() || type->IsObjectOrInterface());
memset(mMemory.mVals + addr, 0, type->mSize);
return true;
}
if (constant->mConstType == BfConstType_GEP32_2) if (constant->mConstType == BfConstType_GEP32_2)
{ {
auto gepConst = (BfConstantGEP32_2*)constant; auto gepConst = (BfConstantGEP32_2*)constant;
@ -4111,8 +4128,7 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns
auto constant = module->mBfIRBuilder->GetConstant(arg); auto constant = module->mBfIRBuilder->GetConstant(arg);
if (paramType->IsComposite()) if (paramType->IsComposite())
{ {
auto paramTypeInst = paramType->ToTypeInstance(); useCompositeAddr -= paramType->mSize;
useCompositeAddr -= paramTypeInst->mInstSize;
if (!WriteConstant(module, useCompositeAddr, constant, paramType, isParams)) if (!WriteConstant(module, useCompositeAddr, constant, paramType, isParams))
{ {
Fail(StrFormat("Failed to process argument for param '%s'", methodInstance->GetParamName(paramIdx).c_str())); Fail(StrFormat("Failed to process argument for param '%s'", methodInstance->GetParamName(paramIdx).c_str()));