1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-23 18:18:00 +02:00

Fixed int-lowered structs with immutable methods in LLVM

This commit is contained in:
Brian Fiete 2020-03-12 05:40:36 -07:00
parent 7a08e7bf11
commit 5276bd4533
4 changed files with 83 additions and 8 deletions

View file

@ -12092,9 +12092,7 @@ BfTypedValue BfModule::GetThis()
return BfTypedValue();
}
bool preferValue = !IsTargetingBeefBackend();
if (useMethodState->mLocals.IsEmpty())
{
// This can happen in rare non-capture cases, such as when we need to do a const expression resolve for a sized-array return type on a local method
@ -12104,9 +12102,18 @@ BfTypedValue BfModule::GetThis()
auto thisLocal = useMethodState->mLocals[0];
BF_ASSERT(thisLocal->mIsThis);
bool preferValue = !IsTargetingBeefBackend();
if (!thisLocal->mAddr)
preferValue = true;
bool usedVal = false;
BfIRValue thisValue;
if ((preferValue) || (!thisLocal->mAddr) /*|| (thisLocal->mIsSplat)*/)
if ((preferValue) && (!thisLocal->mIsLowered))
{
thisValue = thisLocal->mValue;
usedVal = true;
}
else if ((thisLocal->mIsSplat) || (thisLocal->mIsLowered))
thisValue = thisLocal->mAddr;
else

View file

@ -31,9 +31,25 @@ namespace Tests
struct StructC
{
int8 mA;
int32 mB;
int8 mC;
public int8 mA;
public int32 mB;
public int8 mC;
public int A
{
get mut
{
return mA;
}
}
public int B
{
get
{
return mB;
}
}
}
[Ordered]
@ -52,6 +68,28 @@ namespace Tests
int8 mC;
}
[CRepr]
struct Color
{
public uint8 mR, mG, mB, mA;
public uint8 R
{
get mut
{
return mR;
}
}
public uint8 G
{
get
{
return mG;
}
}
}
struct StructF : StructC
{
int8 mD;
@ -134,5 +172,24 @@ namespace Tests
Span<char8> span = sv;
Test.Assert(Test(sv) == 22);
}
[Test]
static void TestProperties()
{
StructC sc = .();
sc.mA = 11;
sc.mB = 22;
sc.mC = 33;
Test.Assert(sc.A == 11);
Test.Assert(sc.B == 22);
Color clr;
clr.mR = 10;
clr.mG = 20;
clr.mB = 30;
clr.mA = 40;
Test.Assert(clr.R == 10);
Test.Assert(clr.G == 20);
}
}
}