mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Null conditional fixes
This commit is contained in:
parent
bb66c77da8
commit
f6752b703d
4 changed files with 15 additions and 1 deletions
|
@ -15485,6 +15485,7 @@ BfTypedValue BfExprEvaluator::SetupNullConditional(BfTypedValue thisValue, BfTok
|
||||||
else
|
else
|
||||||
isNotNull = mModule->mBfIRBuilder->CreateIsNotNull(thisValue.mValue);
|
isNotNull = mModule->mBfIRBuilder->CreateIsNotNull(thisValue.mValue);
|
||||||
BfIRBlock notNullBB = mModule->mBfIRBuilder->CreateBlock("nullCond.notNull");
|
BfIRBlock notNullBB = mModule->mBfIRBuilder->CreateBlock("nullCond.notNull");
|
||||||
|
pendingNullCond->mNotNullBBs.Add(notNullBB);
|
||||||
mModule->mBfIRBuilder->CreateCondBr(isNotNull, notNullBB, pendingNullCond->mDoneBB);
|
mModule->mBfIRBuilder->CreateCondBr(isNotNull, notNullBB, pendingNullCond->mDoneBB);
|
||||||
|
|
||||||
mModule->AddBasicBlock(notNullBB);
|
mModule->AddBasicBlock(notNullBB);
|
||||||
|
|
|
@ -6886,9 +6886,16 @@ BfTypedValue BfModule::FlushNullConditional(BfTypedValue result, bool ignoreNull
|
||||||
AddBasicBlock(pendingNullCond->mDoneBB);
|
AddBasicBlock(pendingNullCond->mDoneBB);
|
||||||
if (nullableType == NULL)
|
if (nullableType == NULL)
|
||||||
{
|
{
|
||||||
auto phi = mBfIRBuilder->CreatePhi(mBfIRBuilder->MapType(result.mType), 2);
|
auto phi = mBfIRBuilder->CreatePhi(mBfIRBuilder->MapType(result.mType), 1 + (int)pendingNullCond->mNotNullBBs.size());
|
||||||
mBfIRBuilder->AddPhiIncoming(phi, result.mValue, notNullBB);
|
mBfIRBuilder->AddPhiIncoming(phi, result.mValue, notNullBB);
|
||||||
|
|
||||||
mBfIRBuilder->AddPhiIncoming(phi, GetDefaultValue(result.mType), pendingNullCond->mCheckBB);
|
mBfIRBuilder->AddPhiIncoming(phi, GetDefaultValue(result.mType), pendingNullCond->mCheckBB);
|
||||||
|
for (int notNullIdx = 0; notNullIdx < (int)pendingNullCond->mNotNullBBs.size() - 1; notNullIdx++)
|
||||||
|
{
|
||||||
|
auto prevNotNullBB = pendingNullCond->mNotNullBBs[notNullIdx];
|
||||||
|
mBfIRBuilder->AddPhiIncoming(phi, GetDefaultValue(result.mType), prevNotNullBB);
|
||||||
|
}
|
||||||
|
|
||||||
result.mValue = phi;
|
result.mValue = phi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -645,6 +645,7 @@ public:
|
||||||
BfIRBlock mPrevBB;
|
BfIRBlock mPrevBB;
|
||||||
BfIRBlock mCheckBB;
|
BfIRBlock mCheckBB;
|
||||||
BfIRBlock mDoneBB;
|
BfIRBlock mDoneBB;
|
||||||
|
SizedArray<BfIRBlock, 4> mNotNullBBs;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BfAttributeState
|
class BfAttributeState
|
||||||
|
|
|
@ -7,6 +7,7 @@ namespace Tests
|
||||||
class CondB
|
class CondB
|
||||||
{
|
{
|
||||||
public int mInt = 123;
|
public int mInt = 123;
|
||||||
|
public String mStr;
|
||||||
|
|
||||||
public int Val
|
public int Val
|
||||||
{
|
{
|
||||||
|
@ -53,6 +54,10 @@ namespace Tests
|
||||||
else
|
else
|
||||||
Test.FatalError();
|
Test.FatalError();
|
||||||
|
|
||||||
|
Test.Assert(ca?.mCondB?.mStr == null);
|
||||||
|
Test.Assert(!(ca?.mCondB?.mStr?.Length != 0));
|
||||||
|
Test.Assert(!(ca?.mCondB?.mStr?.Length == 0));
|
||||||
|
|
||||||
if (let i = ca?.mCondB?.mInt)
|
if (let i = ca?.mCondB?.mInt)
|
||||||
{
|
{
|
||||||
Test.Assert(typeof(decltype(i)) == typeof(int));
|
Test.Assert(typeof(decltype(i)) == typeof(int));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue