From e018c0813420434a665e03587458e55f2957527d Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 28 Oct 2021 09:33:27 -0700 Subject: [PATCH] Sized array encoding fix --- IDEHelper/Compiler/CeMachine.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/IDEHelper/Compiler/CeMachine.cpp b/IDEHelper/Compiler/CeMachine.cpp index fa87296a..352c7366 100644 --- a/IDEHelper/Compiler/CeMachine.cpp +++ b/IDEHelper/Compiler/CeMachine.cpp @@ -3362,7 +3362,17 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta auto aggConstant = (BfConstantAgg*)constant; if (type->IsSizedArray()) { - return false; + 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; + if (!WriteConstant(module, addr + i * sizedArrayType->mElementType->mSize, fieldConstant, sizedArrayType->mElementType)) + return false; + } + + return true; } else if (type->IsArray()) { @@ -3477,6 +3487,13 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta auto constTarget = module->mBfIRBuilder->GetConstantById(constBitCast->mTarget); 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) { @@ -4110,9 +4127,8 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns auto constant = module->mBfIRBuilder->GetConstant(arg); if (paramType->IsComposite()) - { - auto paramTypeInst = paramType->ToTypeInstance(); - useCompositeAddr -= paramTypeInst->mInstSize; + { + useCompositeAddr -= paramType->mSize; if (!WriteConstant(module, useCompositeAddr, constant, paramType, isParams)) { Fail(StrFormat("Failed to process argument for param '%s'", methodInstance->GetParamName(paramIdx).c_str()));