1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fix for unions where union val is non-addr and member is a reference

This commit is contained in:
Brian Fiete 2024-08-12 18:23:49 -04:00
parent 0964d7805e
commit f88e752303

View file

@ -5407,10 +5407,13 @@ BfTypedValue BfExprEvaluator::LoadField(BfAstNode* targetSrc, BfTypedValue targe
auto unionInnerType = typeInstance->GetUnionInnerType(); auto unionInnerType = typeInstance->GetUnionInnerType();
if (unionInnerType != resolvedFieldType) if (unionInnerType != resolvedFieldType)
{ {
if (!retVal.IsAddr()) BfTypedValue unionTypedValue = retVal;
retVal = mModule->MakeAddressable(retVal); unionTypedValue.mType = unionInnerType;
if (!unionTypedValue.IsAddr())
unionTypedValue = mModule->MakeAddressable(unionTypedValue);
BfIRType llvmPtrType = mModule->mBfIRBuilder->GetPointerTo(mModule->mBfIRBuilder->MapType(resolvedFieldType)); BfIRType llvmPtrType = mModule->mBfIRBuilder->GetPointerTo(mModule->mBfIRBuilder->MapType(resolvedFieldType));
retVal.mValue = mModule->mBfIRBuilder->CreateBitCast(retVal.mValue, llvmPtrType); retVal.mValue = mModule->mBfIRBuilder->CreateBitCast(unionTypedValue.mValue, llvmPtrType);
retVal.mKind = unionTypedValue.mKind;
} }
} }