AlignmentCalc: Array alignment should be based on elementType's alignment

This commit is contained in:
Alastair Robertson 2023-07-25 06:09:48 -07:00 committed by Alastair Robertson
parent dfc0c62749
commit df5ae4e34c
2 changed files with 39 additions and 1 deletions

View File

@ -370,7 +370,7 @@ class Array : public Type {
}
virtual uint64_t align() const override {
return elementType_.size();
return elementType_.align();
}
virtual NodeId id() const override {

View File

@ -182,3 +182,41 @@ TEST(AlignmentCalcTest, Bitfields) {
Primitive: int64_t
)");
}
TEST(AlignmentCalcTest, Array) {
test(AlignmentCalc::createPass(), R"(
[0] Class: MyClass (size: 1)
Member: a (offset: 0)
[1] Array: (length: 1)
[2] Class: AlignedClass (size: 1)
Member: b (offset: 0, align: 16)
Primitive: int8_t
)",
R"(
[0] Class: MyClass (size: 1, align: 16, packed)
Member: a (offset: 0, align: 16)
[1] Array: (length: 1)
[2] Class: AlignedClass (size: 1, align: 16, packed)
Member: b (offset: 0, align: 16)
Primitive: int8_t
)");
}
TEST(AlignmentCalcTest, Typedef) {
test(AlignmentCalc::createPass(), R"(
[0] Class: MyClass (size: 1)
Member: a (offset: 0)
[1] Typedef: MyTypedef
[2] Class: AlignedClass (size: 1)
Member: b (offset: 0, align: 16)
Primitive: int8_t
)",
R"(
[0] Class: MyClass (size: 1, align: 16, packed)
Member: a (offset: 0, align: 16)
[1] Typedef: MyTypedef
[2] Class: AlignedClass (size: 1, align: 16, packed)
Member: b (offset: 0, align: 16)
Primitive: int8_t
)");
}