bugfix: tagged unions alignment not always respected
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 22 Jun 2023 23:28:03 +0000 (18:28 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 22 Jun 2023 23:28:03 +0000 (18:28 -0500)
compiler/src/types.c

index 073da57a66dae458d239234de4bf9a3d21e33b34..29c955a9091d7ad5fdf85561e51c677473fde157 100644 (file)
@@ -805,6 +805,9 @@ static Type* type_build_from_ast_inner(bh_allocator alloc, AstType* type_node, b
                 bh_arr_push(tag_enum_node->values, ev);
             }
 
+            alignment = bh_max(alignment, 4);
+            bh_align(size, alignment);
+
             u_type->Union.alignment = alignment;
             u_type->Union.size = size + alignment; // Add the size of the tag
             u_type->Union.tag_type = type_build_from_ast(alloc, (AstType *) tag_enum_node);