hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 574b882cc4dbbef0ad0448778a3e3c28eb88595a
parent cee4722d861261b9458b0a2f99192bba00eb9d62
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  4 May 2021 13:32:35 -0400

hare::types: fix struct alignment

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mhare/types/+test.ha | 3+++
Mhare/types/store.ha | 4++--
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hare/types/+test.ha b/hare/types/+test.ha @@ -43,6 +43,7 @@ fn parse_type(in: str) ast::_type = { defer ast::type_free(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 8); + assert(htype.align == 4); let stype = htype._type as _struct; assert(stype.kind == struct_union::STRUCT); assert(len(stype.fields) == 2); @@ -62,6 +63,7 @@ fn parse_type(in: str) ast::_type = { defer ast::type_free(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 4); + assert(htype.align == 4); let stype = htype._type as _struct; assert(stype.kind == struct_union::UNION); assert(len(stype.fields) == 2); @@ -81,6 +83,7 @@ fn parse_type(in: str) ast::_type = { defer ast::type_free(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 24); + assert(htype.align == 8); let stype = htype._type as _struct; assert(stype.kind == struct_union::STRUCT); diff --git a/hare/types/store.ha b/hare/types/store.ha @@ -194,7 +194,7 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { }, st: ast::struct_type => { let st = struct_from_ast(store, st, false)?; - sz = 0; + sz = 0; align = 0; for (let i = 0z; i < len(st.fields); i += 1) { const field = st.fields[i]; if (field.offs + field._type.sz > sz) { @@ -208,7 +208,7 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { }, un: ast::union_type => { let st = struct_from_ast(store, un, true)?; - sz = 0; + sz = 0; align = 0; for (let i = 0z; i < len(st.fields); i += 1) { const field = st.fields[i]; if (field.offs + field._type.sz > sz) {