Skip to content
Permalink
Browse files

Fixed arrays of dynamic arrays causing a compilation error.

  • Loading branch information...
Doom2fan authored and coelckers committed Mar 13, 2019
1 parent 04bf975 commit 8dea4f9523d1b6091cb9dd876fd6f6449e7d9c8f
Showing with 21 additions and 3 deletions.
  1. +21 −3 src/scripting/backend/codegen.cpp
@@ -7343,6 +7343,10 @@ FxExpression *FxArrayElement::Resolve(FCompileContext &ctx)
auto parentfield = static_cast<FxMemberBase *>(Array)->membervar;
SizeAddr = parentfield->Offset + sizeof(void*);
}
else if (Array->ExprType == EFX_ArrayElement)
{
SizeAddr = ~0u;
}
else
{
ScriptPosition.Message(MSG_ERROR, "Invalid resizable array");
@@ -7415,7 +7419,8 @@ ExpEmit FxArrayElement::Emit(VMFunctionBuilder *build)
ExpEmit arrayvar = Array->Emit(build);
ExpEmit start;
ExpEmit bound;

bool nestedarray = false;

if (SizeAddr != ~0u)
{
bool ismeta = Array->ExprType == EFX_ClassMember && static_cast<FxClassMember*>(Array)->membervar->Flags & VARF_Meta;
@@ -7441,15 +7446,28 @@ ExpEmit FxArrayElement::Emit(VMFunctionBuilder *build)
arraymemberbase->AddressRequested = origaddrreq;
Array->ValueType = origvaluetype;
}
else if (Array->ExprType == EFX_ArrayElement && Array->isStaticArray())
{
bool ismeta = Array->ExprType == EFX_ClassMember && static_cast<FxClassMember*>(Array)->membervar->Flags & VARF_Meta;

arrayvar.Free(build);
start = ExpEmit(build, REGT_POINTER);
build->Emit(OP_LP, start.RegNum, arrayvar.RegNum, build->GetConstantInt(0));

bound = ExpEmit(build, REGT_INT);
build->Emit(OP_LW, bound.RegNum, arrayvar.RegNum, build->GetConstantInt(sizeof(void*)));

nestedarray = true;
}
else start = arrayvar;

if (index->isConstant())
{
unsigned indexval = static_cast<FxConstant *>(index)->GetValue().GetInt();
assert(SizeAddr != ~0u || (indexval < arraytype->ElementCount && "Array index out of bounds"));
assert(SizeAddr != ~0u || nestedarray || (indexval < arraytype->ElementCount && "Array index out of bounds"));

// For resizable arrays we even need to check the bounds if if the index is constant because they are not known at compile time.
if (SizeAddr != ~0u)
if (SizeAddr != ~0u || nestedarray)
{
ExpEmit indexreg(build, REGT_INT);
build->EmitLoadInt(indexreg.RegNum, indexval);

0 comments on commit 8dea4f9

Please sign in to comment.
You can’t perform that action at this time.