mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Fixed crepr union size
This commit is contained in:
parent
682798fe7e
commit
868700b0dd
5 changed files with 15 additions and 35 deletions
|
@ -19286,8 +19286,6 @@ void BfExprEvaluator::InitializedSizedArray(BfSizedArrayType* arrayType, BfToken
|
||||||
elementValue = mModule->GetDefaultTypedValue(checkArrayType->mElementType);
|
elementValue = mModule->GetDefaultTypedValue(checkArrayType->mElementType);
|
||||||
|
|
||||||
// For now, we can't properly create const-valued non-size-aligned composites
|
// For now, we can't properly create const-valued non-size-aligned composites
|
||||||
// if (checkArrayType->mElementType->NeedsExplicitAlignment())
|
|
||||||
// isAllConst = false;
|
|
||||||
if (!elementValue.mValue.IsConst())
|
if (!elementValue.mValue.IsConst())
|
||||||
isAllConst = false;
|
isAllConst = false;
|
||||||
if (elementValue.IsAddr())
|
if (elementValue.IsAddr())
|
||||||
|
|
|
@ -3690,14 +3690,6 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst
|
||||||
|
|
||||||
BfIRType resolvedFieldIRType = MapType(resolvedFieldType);
|
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)
|
if (fieldInstance->mDataOffset > dataPos)
|
||||||
{
|
{
|
||||||
int fillSize = 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);
|
BF_ASSERT((int)irFieldTypes.size() == fieldInstance->mDataIdx);
|
||||||
irFieldTypes.push_back(resolvedFieldIRType);
|
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"
|
auto byteType = mModule->GetPrimitiveType(BfTypeCode_Int8);
|
||||||
int endPad = typeInstance->mInstSize - dataPos;
|
auto arrType = GetSizedArrayType(MapType(byteType), endPad);
|
||||||
if (endPad > 0)
|
irFieldTypes.push_back(arrType);
|
||||||
{
|
dataPos += endPad;
|
||||||
auto byteType = mModule->GetPrimitiveType(BfTypeCode_Int8);
|
|
||||||
auto arrType = GetSizedArrayType(MapType(byteType), endPad);
|
|
||||||
irFieldTypes.push_back(arrType);
|
|
||||||
dataPos += endPad;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4859,8 +4859,6 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool needsExplicitAlignment = !isCRepr || ((typeInstance->mBaseType != NULL) && (!typeInstance->mBaseType->mIsCRepr));
|
|
||||||
|
|
||||||
bool needsExplicitAlignment = true;
|
bool needsExplicitAlignment = true;
|
||||||
|
|
||||||
for (int fieldIdx = 0; fieldIdx < (int)dataFieldVec.size(); fieldIdx++)
|
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);
|
int alignSize = fieldInstance->GetAlign(packing);
|
||||||
fieldInstance->mDataSize = dataSize;
|
fieldInstance->mDataSize = dataSize;
|
||||||
|
|
||||||
//bool needsExplicitAlignment = !isCRepr || resolvedFieldType->NeedsExplicitAlignment();
|
|
||||||
|
|
||||||
int nextDataPos = dataPos;
|
int nextDataPos = dataPos;
|
||||||
nextDataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1);
|
nextDataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1);
|
||||||
int padding = nextDataPos - dataPos;
|
int padding = nextDataPos - dataPos;
|
||||||
|
|
|
@ -2621,8 +2621,8 @@ BfClosureType::~BfClosureType()
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfClosureType::Init(BfProject* bfProject)
|
void BfClosureType::Init(BfProject* bfProject)
|
||||||
{
|
{
|
||||||
auto srcTypeDef = mSrcDelegate->mTypeDef;
|
auto srcTypeDef = mSrcDelegate->mTypeDef;
|
||||||
auto system = mSrcDelegate->mModule->mSystem;
|
auto system = mSrcDelegate->mModule->mSystem;
|
||||||
|
|
||||||
mTypeDef = new BfTypeDef();
|
mTypeDef = new BfTypeDef();
|
||||||
|
|
|
@ -507,8 +507,7 @@ public:
|
||||||
virtual BfModule* GetModule();
|
virtual BfModule* GetModule();
|
||||||
|
|
||||||
int GetStride() { return BF_ALIGN(mSize, mAlign); }
|
int GetStride() { return BF_ALIGN(mSize, mAlign); }
|
||||||
bool IsSizeAligned() { return (mSize == 0) || (mSize % mAlign == 0); }
|
bool IsSizeAligned() { return (mSize == 0) || (mSize % mAlign == 0); }
|
||||||
virtual bool NeedsExplicitAlignment() { return !IsSizeAligned(); }
|
|
||||||
virtual bool IsInstanceOf(BfTypeDef* typeDef) { return false; }
|
virtual bool IsInstanceOf(BfTypeDef* typeDef) { return false; }
|
||||||
|
|
||||||
virtual bool HasBeenReferenced() { return mDefineState != BfTypeDefineState_Undefined; }
|
virtual bool HasBeenReferenced() { return mDefineState != BfTypeDefineState_Undefined; }
|
||||||
|
@ -2029,8 +2028,7 @@ public:
|
||||||
|
|
||||||
int GetEndingInstanceAlignment() { if (mInstSize % mInstAlign == 0) return mInstAlign; return mInstSize % mInstAlign; }
|
int GetEndingInstanceAlignment() { if (mInstSize % mInstAlign == 0) return mInstAlign; return mInstSize % mInstAlign; }
|
||||||
virtual bool HasTypeFailed() override { return mTypeFailed; }
|
virtual bool HasTypeFailed() override { return mTypeFailed; }
|
||||||
virtual bool IsReified() override { return mIsReified; }
|
virtual bool IsReified() override { return mIsReified; }
|
||||||
virtual bool NeedsExplicitAlignment() override { return !IsSizeAligned() || (mPacking != 0); }
|
|
||||||
virtual bool IsDataIncomplete() override { return ((mTypeIncomplete) || (mBaseTypeMayBeIncomplete)) && (!mNeedsMethodProcessing); }
|
virtual bool IsDataIncomplete() override { return ((mTypeIncomplete) || (mBaseTypeMayBeIncomplete)) && (!mNeedsMethodProcessing); }
|
||||||
virtual bool IsFinishingType() override { return mIsFinishingType; }
|
virtual bool IsFinishingType() override { return mIsFinishingType; }
|
||||||
virtual bool IsIncomplete() override { return (mTypeIncomplete) || (mBaseTypeMayBeIncomplete); }
|
virtual bool IsIncomplete() override { return (mTypeIncomplete) || (mBaseTypeMayBeIncomplete); }
|
||||||
|
@ -2451,9 +2449,7 @@ public:
|
||||||
mElementCount = 0;
|
mElementCount = 0;
|
||||||
mGenericDepth = 0;
|
mGenericDepth = 0;
|
||||||
mWantsGCMarking = false;
|
mWantsGCMarking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool NeedsExplicitAlignment() override { return mElementType->NeedsExplicitAlignment(); }
|
|
||||||
|
|
||||||
virtual bool IsSizedArray() override { return true; }
|
virtual bool IsSizedArray() override { return true; }
|
||||||
virtual bool IsUndefSizedArray() override { return mElementCount == -1; }
|
virtual bool IsUndefSizedArray() override { return mElementCount == -1; }
|
||||||
|
@ -2485,8 +2481,6 @@ public:
|
||||||
BfType* mElementCountSource;
|
BfType* mElementCountSource;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool NeedsExplicitAlignment() override { return mElementType->NeedsExplicitAlignment(); }
|
|
||||||
|
|
||||||
virtual bool IsUnknownSizedArrayType() override { return true; }
|
virtual bool IsUnknownSizedArrayType() override { return true; }
|
||||||
|
|
||||||
virtual bool IsWrappableType() override { return true; }
|
virtual bool IsWrappableType() override { return true; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue