From 5125ce83d4d402243bd1f3c7ff2bcbfff6a9e9d5 Mon Sep 17 00:00:00 2001 From: corley <28909106+corleypc@users.noreply.github.com> Date: Sun, 11 Oct 2026 13:46:55 +0300 Subject: [PATCH] fixes packed field zeroing alignment --- src/llvm_backend_utility.cpp | 5 ++++- tests/internal/test_packed_field.odin | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index d6408d0ba..58108a341 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -173,7 +173,10 @@ gb_internal void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, u } break; default: - LLVMBuildStore(p->builder, LLVMConstNull(lb_type(p->module, type)), ptr); + { + LLVMValueRef store = LLVMBuildStore(p->builder, LLVMConstNull(lb_type(p->module, type)), ptr); + lb_lower_store_alignment_to_known(p, store, ptr); + } break; } } diff --git a/tests/internal/test_packed_field.odin b/tests/internal/test_packed_field.odin index 9551a75e6..fb195ed7f 100644 --- a/tests/internal/test_packed_field.odin +++ b/tests/internal/test_packed_field.odin @@ -294,3 +294,28 @@ test_packed_field_array_conv :: proc(t: ^testing.T) { w := #force_no_inline mul_matrix(&m, &p5) testing.expect(t, w == [4]f32{3, 5, 7, 9}) // exact float } + + +// zero stores to a #packed field + +@(export) +p6: Packed_Small + +@(private="file") +zero_v :: proc(p: ^Packed_Small) { + p.v = {} +} + +@(test) +test_packed_field_zero_store :: proc(t: ^testing.T) { + p6.v = {1, 2, 3, 4} + p6.n = -1 + p6.v = {} // folded const GEP + p6.n = 0 + testing.expect(t, simd.to_array(p6.v) == [4]f32{}) + testing.expect(t, p6.n == 0) + + p6.v = {5, 6, 7, 8} + #force_no_inline zero_v(&p6) // GEP with packed metadata + testing.expect(t, simd.to_array(p6.v) == [4]f32{}) +}