authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-05-30 21:55:44+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-05-31 18:04:33+02:00
logebfd3450d9a3338726e1ed8b08a5751b06604cd5
treea74bf6ee7003cb7dbba333866619829c85c58659
parent7e10cf4fbe2a8a379564941be9953ce157d483cc
signaturelock-open Commit is signed but in an unrecognized format.

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.

2 files changed, 6 insertions(+), 2 deletions(-)

src/arch/wasm/CodeGen.zig+2-2
...@@ -1726,8 +1726,8 @@ fn isByRef(ty: Type, target: std.Target) bool {...@@ -1726,8 +1726,8 @@ fn isByRef(ty: Type, target: std.Target) bool {
17261726
1727 .Array,1727 .Array,
1728 .Frame,1728 .Frame,
1729 .Union,1729 => return ty.hasRuntimeBitsIgnoreComptime(),
1730 => {1730 .Union => {
1731 if (ty.castTag(.@"union")) |union_ty| {1731 if (ty.castTag(.@"union")) |union_ty| {
1732 if (union_ty.data.layout == .Packed) {1732 if (union_ty.data.layout == .Packed) {
1733 return ty.abiSize(target) > 8;1733 return ty.abiSize(target) > 8;
src/codegen.zig+4
...@@ -611,6 +611,10 @@ pub fn generateSymbol(...@@ -611,6 +611,10 @@ pub fn generateSymbol(
611 }611 }
612 }612 }
613613
614 if (layout.padding > 0) {
615 try code.writer().writeByteNTimes(0, layout.padding);
616 }
617
614 return Result.ok;618 return Result.ok;
615 },619 },
616 .Optional => {620 .Optional => {