Skip to content

Commit

Permalink
Better union field loading
Browse files Browse the repository at this point in the history
  • Loading branch information
bfiete committed Sep 5, 2022
1 parent d2356a0 commit 03c56b4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions IDEHelper/Compiler/BfExprEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5319,11 +5319,8 @@ BfTypedValue BfExprEvaluator::LoadField(BfAstNode* targetSrc, BfTypedValue targe
return mModule->GetDefaultTypedValue(resolvedFieldType);
}

if ((target.mType->IsUnion()) && (!target.mType->IsValuelessType()))
target = mModule->MakeAddressable(target);

BfTypedValue retVal;
if (target.IsSplat())
if (targetValue.IsSplat())
{
retVal = mModule->ExtractValue(targetValue, fieldInstance, fieldInstance->mDataIdx);
}
Expand Down Expand Up @@ -5351,15 +5348,18 @@ BfTypedValue BfExprEvaluator::LoadField(BfAstNode* targetSrc, BfTypedValue targe
resolvedFieldType, target.IsReadOnly() ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
}
}

if (!retVal.IsSplat())
if (typeInstance->mIsUnion)
{
if (typeInstance->mIsUnion)
auto unionInnerType = typeInstance->GetUnionInnerType();
if (unionInnerType != resolvedFieldType)
{
if (!retVal.IsAddr())
retVal = mModule->MakeAddressable(retVal);
BfIRType llvmPtrType = mModule->mBfIRBuilder->GetPointerTo(mModule->mBfIRBuilder->MapType(resolvedFieldType));
retVal.mValue = mModule->mBfIRBuilder->CreateBitCast(retVal.mValue, llvmPtrType);
}
}
}

if ((fieldDef->mIsVolatile) && (retVal.IsAddr()))
retVal.mKind = BfTypedValueKind_VolatileAddr;
Expand Down

0 comments on commit 03c56b4

Please sign in to comment.