mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Fixed Equals check for non-aligned-size sized arrays
This commit is contained in:
parent
fc21c66b27
commit
af9320ada6
2 changed files with 41 additions and 5 deletions
|
@ -4156,6 +4156,23 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals)
|
|||
{
|
||||
auto sizedArrayType = (BfSizedArrayType*)compareType;
|
||||
|
||||
auto _SizedIndex = [&](BfIRValue target, BfIRValue index)
|
||||
{
|
||||
if (sizedArrayType->mElementType->IsSizeAligned())
|
||||
{
|
||||
auto ptrType = CreatePointerType(sizedArrayType->mElementType);
|
||||
auto ptrValue = mBfIRBuilder->CreateBitCast(target, mBfIRBuilder->MapType(ptrType));
|
||||
auto gepResult = mBfIRBuilder->CreateInBoundsGEP(ptrValue, index);
|
||||
return BfTypedValue(gepResult, sizedArrayType->mElementType, BfTypedValueKind_Addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
auto indexResult = CreateIndexedValue(sizedArrayType->mElementType, target, index);
|
||||
return BfTypedValue(indexResult, sizedArrayType->mElementType, BfTypedValueKind_Addr);
|
||||
}
|
||||
};
|
||||
|
||||
if (sizedArrayType->mElementCount > 6)
|
||||
{
|
||||
auto intPtrType = GetPrimitiveType(BfTypeCode_IntPtr);
|
||||
|
@ -4173,8 +4190,9 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals)
|
|||
mBfIRBuilder->CreateCondBr(cmpRes, doneBB, bodyBB);
|
||||
|
||||
mBfIRBuilder->SetInsertPoint(bodyBB);
|
||||
BfTypedValue leftValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(mCurMethodState->mLocals[0]->mValue, GetDefaultValue(intPtrType), loadedItr), sizedArrayType->mElementType, BfTypedValueKind_Addr);
|
||||
BfTypedValue rightValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(mCurMethodState->mLocals[1]->mValue, GetDefaultValue(intPtrType), loadedItr), sizedArrayType->mElementType, BfTypedValueKind_Addr);
|
||||
|
||||
BfTypedValue leftValue = _SizedIndex(mCurMethodState->mLocals[0]->mValue, loadedItr);
|
||||
BfTypedValue rightValue = _SizedIndex(mCurMethodState->mLocals[1]->mValue, loadedItr);
|
||||
EmitEquals(leftValue, rightValue, exitBB, strictEquals);
|
||||
auto incValue = mBfIRBuilder->CreateAdd(loadedItr, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 1));
|
||||
mBfIRBuilder->CreateStore(incValue, itr);
|
||||
|
@ -4185,9 +4203,9 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals)
|
|||
else
|
||||
{
|
||||
for (int dataIdx = 0; dataIdx < sizedArrayType->mElementCount; dataIdx++)
|
||||
{
|
||||
BfTypedValue leftValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(mCurMethodState->mLocals[0]->mValue, 0, dataIdx), sizedArrayType->mElementType, BfTypedValueKind_Addr);
|
||||
BfTypedValue rightValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(mCurMethodState->mLocals[1]->mValue, 0, dataIdx), sizedArrayType->mElementType, BfTypedValueKind_Addr);
|
||||
{
|
||||
BfTypedValue leftValue = _SizedIndex(mCurMethodState->mLocals[0]->mValue, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, dataIdx));
|
||||
BfTypedValue rightValue = _SizedIndex(mCurMethodState->mLocals[1]->mValue, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, dataIdx));
|
||||
EmitEquals(leftValue, rightValue, exitBB, strictEquals);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,12 @@ namespace Tests
|
|||
{
|
||||
class SizedArrays
|
||||
{
|
||||
struct StructA
|
||||
{
|
||||
public int32 mA;
|
||||
public int8 mB;
|
||||
}
|
||||
|
||||
public static int[8] iArr = .(123, 234, 345, );
|
||||
public static int[?] iArr2 = .(12, 23, 34);
|
||||
|
||||
|
@ -50,6 +56,18 @@ namespace Tests
|
|||
Test.Assert(iArr[1] == 2234);
|
||||
Test.Assert(iArr[2] == 3345);
|
||||
Test.Assert(iArr[3] == 4000);
|
||||
|
||||
StructA[2] arr0 = default;
|
||||
StructA[2] arr1 = default;
|
||||
Test.Assert(arr0 == arr1);
|
||||
arr0[1].mA = 1;
|
||||
Test.Assert(arr0 != arr1);
|
||||
|
||||
StructA[20] arr2 = default;
|
||||
StructA[20] arr3 = default;
|
||||
Test.Assert(arr2 == arr3);
|
||||
arr2[1].mA = 1;
|
||||
Test.Assert(arr2 != arr3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue