From 8470c6eda2cebcba80ee2f4ce289d86618c605ae Mon Sep 17 00:00:00 2001 From: kalsprite Date: Wed, 12 Aug 2026 23:08:26 -0700 Subject: [PATCH] i386 64-bit scalar alignment --- src/types.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/types.cpp b/src/types.cpp index 13d335348..942917e30 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -4539,7 +4539,13 @@ gb_internal i64 type_align_of_internal(Type *t, TypePath *path) { // NOTE(bill): Things that are bigger than build_context.ptr_size, are actually comprised of smaller types // TODO(bill): Is this correct for 128-bit types (integers)? - return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, build_context.max_align); + i64 max_align = build_context.max_align; + if (build_context.metrics.arch == TargetArch_i386 && + build_context.metrics.os != TargetOs_windows) { + // the i386 System V psABI aligns every scalar to at most 4, unlike Windows + max_align = gb_min(max_align, 4); + } + return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, max_align); } gb_internal i64 *type_set_offsets_of(Slice const &fields, bool is_packed, bool is_raw_union, i64 min_field_align, i64 max_field_align) {