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

Fixed deriving from "valueless" crepr struct

This commit is contained in:
Brian Fiete 2025-03-28 08:09:22 -04:00
parent fe1aa3c26e
commit eb41a9c1de
3 changed files with 29 additions and 1 deletions

View file

@ -4615,7 +4615,15 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
typeInstance->mInstSize = baseTypeInst->mInstSize; typeInstance->mInstSize = baseTypeInst->mInstSize;
typeInstance->mInstAlign = baseTypeInst->mInstAlign; typeInstance->mInstAlign = baseTypeInst->mInstAlign;
typeInstance->mAlign = baseTypeInst->mAlign; typeInstance->mAlign = baseTypeInst->mAlign;
typeInstance->mSize = baseTypeInst->mSize; typeInstance->mSize = baseTypeInst->mSize;
if (baseTypeInst->IsValuelessCReprType())
{
typeInstance->mInstSize = 0;
if (typeInstance->IsValueType())
typeInstance->mSize = 0;
}
typeInstance->mHasPackingHoles = baseTypeInst->mHasPackingHoles; typeInstance->mHasPackingHoles = baseTypeInst->mHasPackingHoles;
if (baseTypeInst->mIsTypedPrimitive) if (baseTypeInst->mIsTypedPrimitive)
typeInstance->mIsTypedPrimitive = true; typeInstance->mIsTypedPrimitive = true;

View file

@ -2861,6 +2861,25 @@ bool BfTypeInstance::IsValuelessType()
return false; return false;
} }
bool BfTypeInstance::IsValuelessCReprType()
{
if (!mIsCRepr)
return false;
if (mInstSize > 1)
return false;
if ((mBaseType->mIsCRepr) && (!IsValuelessCReprType()))
return false;
BF_ASSERT((mDefineState >= BfTypeDefineState_Defined) || (mTypeFailed));
for (auto& fieldInst : mFieldInstances)
{
if (fieldInst.mDataIdx >= 0)
return false;
}
return true;
}
bool BfTypeInstance::IsIRFuncUsed(BfIRFunction func) bool BfTypeInstance::IsIRFuncUsed(BfIRFunction func)
{ {
for (auto& group : mMethodInstanceGroups) for (auto& group : mMethodInstanceGroups)

View file

@ -2175,6 +2175,7 @@ public:
//virtual bool IsValuelessType() override { return (mIsTypedPrimitive) && (mInstSize == 0); } //virtual bool IsValuelessType() override { return (mIsTypedPrimitive) && (mInstSize == 0); }
virtual bool CanBeValuelessType() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); } virtual bool CanBeValuelessType() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); }
virtual bool IsValuelessType() override; virtual bool IsValuelessType() override;
virtual bool IsValuelessCReprType();
virtual bool HasPackingHoles() override { return mHasPackingHoles; } virtual bool HasPackingHoles() override { return mHasPackingHoles; }
virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) override; virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) override;
virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) override; virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) override;