Skip to content

Commit 30d1e05

Browse files
committed
Add alignment support for UnboundedArrayType
Signed-off-by: Roberto Raggi <[email protected]>
1 parent aaeda69 commit 30d1e05

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ node_modules
88
.cache
99
.clangd
1010
*.pch
11+
__pycache__
12+
*.pyc

src/parser/cxx/memory_layout.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ struct AlignmentOf {
255255
return type->symbol()->alignment();
256256
}
257257

258+
auto operator()(const UnboundedArrayType* type) const
259+
-> std::optional<std::size_t> {
260+
return memoryLayout.alignmentOf(type->elementType());
261+
}
262+
258263
auto operator()(auto type) const -> std::optional<std::size_t> {
259264
// ### TODO
260265
if (!type) return std::nullopt;

tests/unit_tests/sema/alignof_01.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ static_assert(alignof(long) == 4);
2222
static_assert(alignof(unsigned long) == 4);
2323
static_assert(alignof(long double) == 16);
2424
#endif
25+
26+
static_assert(alignof(char[]) == 1);
27+
static_assert(alignof(int[]) == 4);
28+
static_assert(alignof(double[]) == 8);
29+
static_assert(alignof(__int128_t) == 16);

0 commit comments

Comments
 (0)