1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Fixed indexing of const multi-dim arrays

This commit is contained in:
Brian Fiete 2025-02-03 08:20:35 -08:00
parent e0529caee0
commit 60fdfff8d7

View file

@ -22653,6 +22653,8 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
if ((!target.IsAddr()) && (!target.mType->IsSizeAligned()))
mModule->MakeAddressable(target);
mResult = BfTypedValue();
mModule->PopulateType(underlyingType);
if ((sizedArrayType->IsUndefSizedArray()) || (isUndefIndex))
{
@ -22669,25 +22671,16 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
}
else if (target.IsAddr())
{
if (target.mType->IsSizeAligned())
{
auto gepResult = mModule->mBfIRBuilder->CreateInBoundsGEP(target.mValue, mModule->GetConstValue(0), indexArgument.mValue);
mResult = BfTypedValue(gepResult, underlyingType, target.IsReadOnly() ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
}
else
{
auto indexResult = mModule->CreateIndexedValue(underlyingType, target.mValue, indexArgument.mValue);
mResult = BfTypedValue(indexResult, underlyingType, target.IsReadOnly() ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
}
// Handle below
}
else
{
if ((!target.mValue.IsConst()) && (!indexArgument.mValue.IsConst()))
{
mModule->Fail("Unable to index value", indexerExpr->mTarget);
return;
target = mModule->MakeAddressable(target);
}
else
{
mModule->mBfIRBuilder->PopulateType(target.mType);
auto gepResult = mModule->mBfIRBuilder->CreateExtractValue(target.mValue, indexArgument.mValue);
@ -22709,6 +22702,27 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
mResult = BfTypedValue(gepResult, underlyingType, BfTypedValueKind_Value);
}
}
if ((!mResult) && (target.IsAddr()))
{
if (target.mType->IsSizeAligned())
{
auto gepResult = mModule->mBfIRBuilder->CreateInBoundsGEP(target.mValue, mModule->GetConstValue(0), indexArgument.mValue);
mResult = BfTypedValue(gepResult, underlyingType, target.IsReadOnly() ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
}
else
{
auto indexResult = mModule->CreateIndexedValue(underlyingType, target.mValue, indexArgument.mValue);
mResult = BfTypedValue(indexResult, underlyingType, target.IsReadOnly() ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
}
}
if (!mResult)
{
mModule->Fail("Unable to index value", indexerExpr->mTarget);
return;
}
}
else
{
// We are no longer accessing data within this type