mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 04:52:21 +02:00
Fixed null coalescing issues with addrs and cast insert points
This commit is contained in:
parent
392b2e0b6c
commit
4189d10f41
1 changed files with 16 additions and 3 deletions
|
@ -20553,6 +20553,8 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
{
|
{
|
||||||
if ((leftValue) && ((leftValue.mType->IsPointer()) || (leftValue.mType->IsFunction()) || (leftValue.mType->IsObject())))
|
if ((leftValue) && ((leftValue.mType->IsPointer()) || (leftValue.mType->IsFunction()) || (leftValue.mType->IsObject())))
|
||||||
{
|
{
|
||||||
|
leftValue = mModule->LoadValue(leftValue);
|
||||||
|
|
||||||
auto prevBB = mModule->mBfIRBuilder->GetInsertBlock();
|
auto prevBB = mModule->mBfIRBuilder->GetInsertBlock();
|
||||||
|
|
||||||
auto rhsBB = mModule->mBfIRBuilder->CreateBlock("nullc.rhs");
|
auto rhsBB = mModule->mBfIRBuilder->CreateBlock("nullc.rhs");
|
||||||
|
@ -20564,7 +20566,7 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
mModule->mBfIRBuilder->CreateIntToPtr(leftValue.mValue, mModule->mBfIRBuilder->MapType(mModule->GetPrimitiveType(BfTypeCode_NullPtr))));
|
mModule->mBfIRBuilder->CreateIntToPtr(leftValue.mValue, mModule->mBfIRBuilder->MapType(mModule->GetPrimitiveType(BfTypeCode_NullPtr))));
|
||||||
else
|
else
|
||||||
isNull = mModule->mBfIRBuilder->CreateIsNull(leftValue.mValue);
|
isNull = mModule->mBfIRBuilder->CreateIsNull(leftValue.mValue);
|
||||||
mModule->mBfIRBuilder->CreateCondBr(isNull, rhsBB, endBB);
|
|
||||||
|
|
||||||
mModule->AddBasicBlock(rhsBB);
|
mModule->AddBasicBlock(rhsBB);
|
||||||
BfTypedValue rightValue;
|
BfTypedValue rightValue;
|
||||||
|
@ -20572,12 +20574,15 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
rightValue = mModule->CreateValueFromExpression(rightExpression, wantType, (BfEvalExprFlags)((mBfEvalExprFlags & BfEvalExprFlags_InheritFlags)));
|
rightValue = mModule->CreateValueFromExpression(rightExpression, wantType, (BfEvalExprFlags)((mBfEvalExprFlags & BfEvalExprFlags_InheritFlags)));
|
||||||
else
|
else
|
||||||
rightValue = mModule->CreateValueFromExpression(rightExpression, wantType, (BfEvalExprFlags)((mBfEvalExprFlags & BfEvalExprFlags_InheritFlags) | BfEvalExprFlags_NoCast));
|
rightValue = mModule->CreateValueFromExpression(rightExpression, wantType, (BfEvalExprFlags)((mBfEvalExprFlags & BfEvalExprFlags_InheritFlags) | BfEvalExprFlags_NoCast));
|
||||||
|
|
||||||
if (!rightValue)
|
if (!rightValue)
|
||||||
{
|
{
|
||||||
mModule->AssertErrorState();
|
mModule->AssertErrorState();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (assignTo == NULL)
|
rightValue = mModule->LoadValue(rightValue);
|
||||||
|
|
||||||
|
if (assignTo == NULL)
|
||||||
{
|
{
|
||||||
auto rightToLeftValue = mModule->CastToValue(rightExpression, rightValue, leftValue.mType, BfCastFlags_SilentFail);
|
auto rightToLeftValue = mModule->CastToValue(rightExpression, rightValue, leftValue.mType, BfCastFlags_SilentFail);
|
||||||
if (rightToLeftValue)
|
if (rightToLeftValue)
|
||||||
|
@ -20586,6 +20591,8 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
mModule->mBfIRBuilder->SetInsertPoint(prevBB);
|
||||||
|
|
||||||
auto leftToRightValue = mModule->CastToValue(leftExpression, leftValue, rightValue.mType, BfCastFlags_SilentFail);
|
auto leftToRightValue = mModule->CastToValue(leftExpression, leftValue, rightValue.mType, BfCastFlags_SilentFail);
|
||||||
if (leftToRightValue)
|
if (leftToRightValue)
|
||||||
{
|
{
|
||||||
|
@ -20598,6 +20605,8 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
mModule->TypeToString(leftValue.mType).c_str(), mModule->TypeToString(rightValue.mType).c_str()), opToken);
|
mModule->TypeToString(leftValue.mType).c_str(), mModule->TypeToString(rightValue.mType).c_str()), opToken);
|
||||||
leftValue = mModule->GetDefaultTypedValue(rightValue.mType);
|
leftValue = mModule->GetDefaultTypedValue(rightValue.mType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mModule->mBfIRBuilder->SetInsertPoint(rhsBB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20605,8 +20614,12 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
mModule->mBfIRBuilder->CreateStore(rightValue.mValue, assignTo->mValue);
|
mModule->mBfIRBuilder->CreateStore(rightValue.mValue, assignTo->mValue);
|
||||||
|
|
||||||
mModule->mBfIRBuilder->CreateBr(endBB);
|
mModule->mBfIRBuilder->CreateBr(endBB);
|
||||||
|
|
||||||
auto endRhsBB = mModule->mBfIRBuilder->GetInsertBlock();
|
auto endRhsBB = mModule->mBfIRBuilder->GetInsertBlock();
|
||||||
|
|
||||||
|
// Actually add CondBr at start
|
||||||
|
mModule->mBfIRBuilder->SetInsertPoint(prevBB);
|
||||||
|
mModule->mBfIRBuilder->CreateCondBr(isNull, rhsBB, endBB);
|
||||||
|
|
||||||
mModule->AddBasicBlock(endBB);
|
mModule->AddBasicBlock(endBB);
|
||||||
|
|
||||||
if (assignTo != NULL)
|
if (assignTo != NULL)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue