mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Fix unions with base types
This commit is contained in:
parent
e6cbf0509b
commit
f9d5b58102
3 changed files with 17 additions and 4 deletions
|
@ -3179,7 +3179,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type)
|
||||||
auto resolvedFieldDIType = DbgGetType(fieldType);
|
auto resolvedFieldDIType = DbgGetType(fieldType);
|
||||||
String fieldName = "$bfunion";
|
String fieldName = "$bfunion";
|
||||||
auto memberType = DbgCreateMemberType(diForwardDecl, fieldName, fileDIScope, lineNum,
|
auto memberType = DbgCreateMemberType(diForwardDecl, fieldName, fileDIScope, lineNum,
|
||||||
fieldType->mSize * 8, fieldType->mAlign * 8, 0,
|
fieldType->mSize * 8, fieldType->mAlign * 8, typeInstance->mBaseType->mInstSize * 8,
|
||||||
flags, resolvedFieldDIType);
|
flags, resolvedFieldDIType);
|
||||||
diFieldTypes.push_back(memberType);
|
diFieldTypes.push_back(memberType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5433,8 +5433,8 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
||||||
{
|
{
|
||||||
BF_ASSERT(resolvedFieldType->mSize >= 0);
|
BF_ASSERT(resolvedFieldType->mSize >= 0);
|
||||||
|
|
||||||
if (alignSize > 1)
|
// if (alignSize > 1)
|
||||||
dataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1);
|
// dataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1);
|
||||||
fieldInstance->mDataOffset = dataPos;
|
fieldInstance->mDataOffset = dataPos;
|
||||||
|
|
||||||
typeInstance->mInstAlign = std::max(typeInstance->mInstAlign, alignSize);
|
typeInstance->mInstAlign = std::max(typeInstance->mInstAlign, alignSize);
|
||||||
|
@ -5623,7 +5623,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
||||||
|
|
||||||
if (unionInnerType != NULL)
|
if (unionInnerType != NULL)
|
||||||
{
|
{
|
||||||
dataPos = unionInnerType->mSize;
|
dataPos = startDataPos + unionInnerType->mSize;
|
||||||
typeInstance->mInstAlign = BF_MAX(unionInnerType->mAlign, typeInstance->mInstAlign);
|
typeInstance->mInstAlign = BF_MAX(unionInnerType->mAlign, typeInstance->mInstAlign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,12 @@ namespace Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Union]
|
||||||
|
struct UnionD : UnionC
|
||||||
|
{
|
||||||
|
public int16 mInt16;
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
static void TestBasics()
|
static void TestBasics()
|
||||||
{
|
{
|
||||||
|
@ -41,6 +47,13 @@ namespace Tests
|
||||||
*((float*)&ub.mInt32) = 1.2f;
|
*((float*)&ub.mInt32) = 1.2f;
|
||||||
Test.Assert(ub.mFloat == 1.2f);
|
Test.Assert(ub.mFloat == 1.2f);
|
||||||
Test.Assert(sizeof(UnionB) == 4);
|
Test.Assert(sizeof(UnionB) == 4);
|
||||||
|
|
||||||
|
UnionD ud = .();
|
||||||
|
ud.mInt32 = 123;
|
||||||
|
ud.mInt16 = 234;
|
||||||
|
Test.Assert(sizeof(UnionD) == 6);
|
||||||
|
Test.Assert(alignof(UnionD) == 4);
|
||||||
|
Test.Assert(((int16*)&ud)[3] == 234);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue