mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Fixes to "valueless" crepr structs
This commit is contained in:
parent
eb41a9c1de
commit
5c11c2271e
4 changed files with 29 additions and 5 deletions
|
@ -3784,7 +3784,14 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst
|
|||
SizedArray<BfIRType, 256> irFieldTypes;
|
||||
if ((!typeInstance->IsTypedPrimitive()) && (typeInstance->mBaseType != NULL))
|
||||
{
|
||||
irFieldTypes.push_back(MapTypeInst(typeInstance->mBaseType, BfIRPopulateType_Eventually_Full));
|
||||
if (typeInstance->mBaseType->IsValuelessCReprType())
|
||||
{
|
||||
// Fake an empty type to avoid having a one-byte base type
|
||||
auto valueTypeType = mModule->ResolveTypeDef(mModule->mCompiler->mValueTypeTypeDef);
|
||||
irFieldTypes.push_back(MapType(valueTypeType, BfIRPopulateType_Eventually_Full));
|
||||
}
|
||||
else
|
||||
irFieldTypes.push_back(MapTypeInst(typeInstance->mBaseType, BfIRPopulateType_Eventually_Full));
|
||||
}
|
||||
|
||||
SizedArray<BfIRMDNode, 256> diFieldTypes;
|
||||
|
|
|
@ -2880,6 +2880,20 @@ bool BfTypeInstance::IsValuelessCReprType()
|
|||
return true;
|
||||
}
|
||||
|
||||
BfTypeInstance* BfTypeInstance::GetBaseType(bool remapValuelessCRepr)
|
||||
{
|
||||
if (!remapValuelessCRepr)
|
||||
return mBaseType;
|
||||
auto checkType = mBaseType;
|
||||
while (checkType != NULL)
|
||||
{
|
||||
if (!checkType->IsValuelessCReprType())
|
||||
break;
|
||||
checkType = checkType->mBaseType;
|
||||
}
|
||||
return checkType;
|
||||
}
|
||||
|
||||
bool BfTypeInstance::IsIRFuncUsed(BfIRFunction func)
|
||||
{
|
||||
for (auto& group : mMethodInstanceGroups)
|
||||
|
|
|
@ -2176,6 +2176,7 @@ public:
|
|||
virtual bool CanBeValuelessType() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); }
|
||||
virtual bool IsValuelessType() override;
|
||||
virtual bool IsValuelessCReprType();
|
||||
virtual BfTypeInstance* GetBaseType(bool remapValuelessCRepr = false);
|
||||
virtual bool HasPackingHoles() override { return mHasPackingHoles; }
|
||||
virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) override;
|
||||
virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) override;
|
||||
|
|
|
@ -4492,10 +4492,11 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta
|
|||
auto typeInst = type->ToTypeInstance();
|
||||
int idx = 0;
|
||||
|
||||
if (typeInst->mBaseType != NULL)
|
||||
auto baseType = typeInst->GetBaseType(true);
|
||||
if (baseType != NULL)
|
||||
{
|
||||
auto baseConstant = module->mBfIRBuilder->GetConstant(aggConstant->mValues[0]);
|
||||
if (!WriteConstant(module, addr, baseConstant, typeInst->mBaseType))
|
||||
if (!WriteConstant(module, addr, baseConstant, baseType))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5034,9 +5035,10 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
|
|||
return irBuilder->CreateConstNull(irBuilder->MapType(typeInst));
|
||||
}
|
||||
|
||||
if (typeInst->mBaseType != NULL)
|
||||
auto baseType = typeInst->GetBaseType(true);
|
||||
if (baseType != NULL)
|
||||
{
|
||||
auto result = CreateConstant(module, instData, typeInst->mBaseType);
|
||||
auto result = CreateConstant(module, instData, baseType);
|
||||
if (!result)
|
||||
return BfIRValue();
|
||||
fieldVals.Add(result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue