From ebfd3450d9a3338726e1ed8b08a5751b06604cd5 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Tue, 30 May 2023 21:55:44 +0200 Subject: [PATCH] codegen: Write padding bytes for unions Previously we did not write any missing padding bytes after the smallest field (either tag or payload, depending on alignment). This resulted in writing too few bytes and not matching the full abisize of the union. --- src/arch/wasm/CodeGen.zig | 4 ++-- src/codegen.zig | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 2072ff15062b85ac291824c04335b1e4ec46a44a..d4be9bf13969a677874143391a0c3c8505d76f9f 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1726,8 +1726,8 @@ fn isByRef(ty: Type, target: std.Target) bool { .Array, .Frame, - .Union, - => { + => return ty.hasRuntimeBitsIgnoreComptime(), + .Union => { if (ty.castTag(.@"union")) |union_ty| { if (union_ty.data.layout == .Packed) { return ty.abiSize(target) > 8; diff --git a/src/codegen.zig b/src/codegen.zig index 692c55e3807d84b366b1eb975094577efd1c769c..adce183833d262c2e1acab40c2a7cb3644ff6fcd 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -611,6 +611,10 @@ pub fn generateSymbol( } } + if (layout.padding > 0) { + try code.writer().writeByteNTimes(0, layout.padding); + } + return Result.ok; }, .Optional => { -- 2.54.0