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

Fixed struct ref casts

This commit is contained in:
Brian Fiete 2022-06-25 08:43:55 -07:00
parent e3cceff39c
commit 487787b08e

View file

@ -12597,9 +12597,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
// Ref X to Ref Y, X* to Y*
{
bool checkUnderlying = false;
bool isRef = false;
if (((typedVal.mType->IsRef()) && (toType->IsRef())))
{
isRef = true;
auto fromRefType = (BfRefType*)typedVal.mType;
auto toRefType = (BfRefType*)toType;
if (fromRefType->mRefKind == toRefType->mRefKind)
@ -12639,12 +12641,24 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
if (matches)
{
// This is either a ref or a ptr so we don't need to set the "IsAddr" flag
typedVal = MakeAddressable(typedVal);
typedVal = MakeAddressable(typedVal);
return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapType(toType));
}
}
}
if ((isRef) && (fromInner->IsStruct()) && (toInner->IsStruct()))
{
if (TypeIsSubTypeOf(fromInner->ToTypeInstance(), toInner->ToTypeInstance()))
{
if (toInner->IsValuelessType())
return mBfIRBuilder->GetFakeVal();
// Is this valid?
typedVal = MakeAddressable(typedVal);
return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapType(toType));
}
}
// ref int <-> ref int64/int32 (of same size)
if (((fromInner->IsInteger()) && (toInner->IsInteger())) &&
(fromInner->mSize == toInner->mSize) &&