mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixed indexing of const multi-dim arrays
This commit is contained in:
parent
e0529caee0
commit
60fdfff8d7
1 changed files with 40 additions and 26 deletions
|
@ -22653,6 +22653,8 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
|
||||||
if ((!target.IsAddr()) && (!target.mType->IsSizeAligned()))
|
if ((!target.IsAddr()) && (!target.mType->IsSizeAligned()))
|
||||||
mModule->MakeAddressable(target);
|
mModule->MakeAddressable(target);
|
||||||
|
|
||||||
|
mResult = BfTypedValue();
|
||||||
|
|
||||||
mModule->PopulateType(underlyingType);
|
mModule->PopulateType(underlyingType);
|
||||||
if ((sizedArrayType->IsUndefSizedArray()) || (isUndefIndex))
|
if ((sizedArrayType->IsUndefSizedArray()) || (isUndefIndex))
|
||||||
{
|
{
|
||||||
|
@ -22669,25 +22671,16 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
|
||||||
}
|
}
|
||||||
else if (target.IsAddr())
|
else if (target.IsAddr())
|
||||||
{
|
{
|
||||||
if (target.mType->IsSizeAligned())
|
// Handle below
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((!target.mValue.IsConst()) && (!indexArgument.mValue.IsConst()))
|
if ((!target.mValue.IsConst()) && (!indexArgument.mValue.IsConst()))
|
||||||
{
|
{
|
||||||
mModule->Fail("Unable to index value", indexerExpr->mTarget);
|
target = mModule->MakeAddressable(target);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
mModule->mBfIRBuilder->PopulateType(target.mType);
|
mModule->mBfIRBuilder->PopulateType(target.mType);
|
||||||
auto gepResult = mModule->mBfIRBuilder->CreateExtractValue(target.mValue, indexArgument.mValue);
|
auto gepResult = mModule->mBfIRBuilder->CreateExtractValue(target.mValue, indexArgument.mValue);
|
||||||
|
|
||||||
|
@ -22709,6 +22702,27 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
|
||||||
mResult = BfTypedValue(gepResult, underlyingType, BfTypedValueKind_Value);
|
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
|
else
|
||||||
{
|
{
|
||||||
// We are no longer accessing data within this type
|
// We are no longer accessing data within this type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue