1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Fixed crepr union size

This commit is contained in:
Brian Fiete 2022-02-15 10:27:04 -05:00
parent 682798fe7e
commit 868700b0dd
5 changed files with 15 additions and 35 deletions

View file

@ -19286,8 +19286,6 @@ void BfExprEvaluator::InitializedSizedArray(BfSizedArrayType* arrayType, BfToken
elementValue = mModule->GetDefaultTypedValue(checkArrayType->mElementType);
// For now, we can't properly create const-valued non-size-aligned composites
// if (checkArrayType->mElementType->NeedsExplicitAlignment())
// isAllConst = false;
if (!elementValue.mValue.IsConst())
isAllConst = false;
if (elementValue.IsAddr())

View file

@ -3690,14 +3690,6 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst
BfIRType resolvedFieldIRType = MapType(resolvedFieldType);
//bool needsExplicitAlignment = !isCRepr || resolvedFieldType->NeedsExplicitAlignment();
bool needsExplicitAlignment = true;
if (!needsExplicitAlignment)
{
int alignSize = resolvedFieldType->mAlign;
dataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1);
}
if (fieldInstance->mDataOffset > dataPos)
{
int fillSize = fieldInstance->mDataOffset - dataPos;
@ -3710,18 +3702,18 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst
BF_ASSERT((int)irFieldTypes.size() == fieldInstance->mDataIdx);
irFieldTypes.push_back(resolvedFieldIRType);
}
if ((isCRepr) && (needsExplicitAlignment) && (fieldIdx == (int)orderedFields.size() - 1))
if (isCRepr)
{
// Add explicit padding at end to enforce the "aligned size"
int endPad = typeInstance->mInstSize - dataPos;
if (endPad > 0)
{
// Add explicit padding at end to enforce the "aligned size"
int endPad = typeInstance->mInstSize - dataPos;
if (endPad > 0)
{
auto byteType = mModule->GetPrimitiveType(BfTypeCode_Int8);
auto arrType = GetSizedArrayType(MapType(byteType), endPad);
irFieldTypes.push_back(arrType);
dataPos += endPad;
}
auto byteType = mModule->GetPrimitiveType(BfTypeCode_Int8);
auto arrType = GetSizedArrayType(MapType(byteType), endPad);
irFieldTypes.push_back(arrType);
dataPos += endPad;
}
}

View file

@ -4859,8 +4859,6 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
}
}
//bool needsExplicitAlignment = !isCRepr || ((typeInstance->mBaseType != NULL) && (!typeInstance->mBaseType->mIsCRepr));
bool needsExplicitAlignment = true;
for (int fieldIdx = 0; fieldIdx < (int)dataFieldVec.size(); fieldIdx++)
@ -4873,8 +4871,6 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
int alignSize = fieldInstance->GetAlign(packing);
fieldInstance->mDataSize = dataSize;
//bool needsExplicitAlignment = !isCRepr || resolvedFieldType->NeedsExplicitAlignment();
int nextDataPos = dataPos;
nextDataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1);
int padding = nextDataPos - dataPos;

View file

@ -2621,8 +2621,8 @@ BfClosureType::~BfClosureType()
}
void BfClosureType::Init(BfProject* bfProject)
{
auto srcTypeDef = mSrcDelegate->mTypeDef;
{
auto srcTypeDef = mSrcDelegate->mTypeDef;
auto system = mSrcDelegate->mModule->mSystem;
mTypeDef = new BfTypeDef();

View file

@ -507,8 +507,7 @@ public:
virtual BfModule* GetModule();
int GetStride() { return BF_ALIGN(mSize, mAlign); }
bool IsSizeAligned() { return (mSize == 0) || (mSize % mAlign == 0); }
virtual bool NeedsExplicitAlignment() { return !IsSizeAligned(); }
bool IsSizeAligned() { return (mSize == 0) || (mSize % mAlign == 0); }
virtual bool IsInstanceOf(BfTypeDef* typeDef) { return false; }
virtual bool HasBeenReferenced() { return mDefineState != BfTypeDefineState_Undefined; }
@ -2029,8 +2028,7 @@ public:
int GetEndingInstanceAlignment() { if (mInstSize % mInstAlign == 0) return mInstAlign; return mInstSize % mInstAlign; }
virtual bool HasTypeFailed() override { return mTypeFailed; }
virtual bool IsReified() override { return mIsReified; }
virtual bool NeedsExplicitAlignment() override { return !IsSizeAligned() || (mPacking != 0); }
virtual bool IsReified() override { return mIsReified; }
virtual bool IsDataIncomplete() override { return ((mTypeIncomplete) || (mBaseTypeMayBeIncomplete)) && (!mNeedsMethodProcessing); }
virtual bool IsFinishingType() override { return mIsFinishingType; }
virtual bool IsIncomplete() override { return (mTypeIncomplete) || (mBaseTypeMayBeIncomplete); }
@ -2451,9 +2449,7 @@ public:
mElementCount = 0;
mGenericDepth = 0;
mWantsGCMarking = false;
}
virtual bool NeedsExplicitAlignment() override { return mElementType->NeedsExplicitAlignment(); }
}
virtual bool IsSizedArray() override { return true; }
virtual bool IsUndefSizedArray() override { return mElementCount == -1; }
@ -2485,8 +2481,6 @@ public:
BfType* mElementCountSource;
public:
virtual bool NeedsExplicitAlignment() override { return mElementType->NeedsExplicitAlignment(); }
virtual bool IsUnknownSizedArrayType() override { return true; }
virtual bool IsWrappableType() override { return true; }